Hi guys,
Any idea how to get the selected instance name in Flex repeater?
Like when I select Instance[25] then get the role name in the custom parameter.
Thanks,
Priyanka
Hi guys,
Any idea how to get the selected instance name in Flex repeater?
Like when I select Instance[25] then get the role name in the custom parameter.
Thanks,
Priyanka
What are the array items 24 - 28? Are they flex repeater instance view parameters? (I'm confused because when I create a flex repeater each instance has instanceStyle and instancePosition properties and yours does not. Did you create the array by script?)
You don't need either of these, I usually delete them if I don't use them
These params will get pass automatically into your embedded Views as parameters. So if you have role and selected params in your embedded View, then the values will appear in them
If you want the main view to know which repeater view has been selected then I would use system.perspective.sendMessage in an onClick event on the root of the embedded view.
def runAction(self, event):
role = self.view.params.role
system.perspective.sendMessage("repeaterViewClicked", {"role": role}, scope = "page")
Then use a message handler on the component in the main view that needs the information. Be sure to set the listen scope to "Page".
May I suggest a slight rework of this script ?
Because frankly this is a weird and convoluted way of doing it.
return next(instance.role for instance in value if instance.get(selected))
For some reason this made me remember the words of an old mentor. He would say: "Where were you when the page was blank!"
I didn't have much time earlier, but now I'd like to expand a bit.
There's a slight difference in functionality between both our scripts. It stems from an assumption I made, which is that only one instance should be selected at a time.
So, my script returns the role associated with the first selected instance encountered.
Yours will return the last one.
Which is equivalent if only one is selected.
If you DO want the last one, then you can use the script I provided, with one small change: reverse the order of value
:
return next(instance.role for instance in reverse(value) if instance.get(selected))
Now, why do I think your script is weird and convoluted ?
You want to return ONE thing, but you're building a list. A list from which you pick the last element, every time you append something.
There are a few things that are really, really unnecessary about this.
val = instance.role
and get rid of the list ?return rolelist[-1]
insteadreturn instance.role
While you may have "resolved" the issue with the post currently marked as a solution, this post is the correct way to manage this: How to get selected instance name in flex repeater - #5 by Transistor
With the code provided and a configured Message Handler listening for repeaterViewClicked
you'll be able to configure a script to execute any time a user clicks an instance.
The code provided in this post is NOT a good way to go about this as you'll always get the instance with the highest index, even if it was not the most recent instance selected.