Flex Repeater - Get Selected Instance

Is there a way to figure out what instance of a template that is selected on a Flex repeater? For an example, If i am currently showing 10 instances of a template, I would like to know what instance a user selects. This is similar to getting data out of a template repeater by using the .getLoadedTemplates() method in Vision.

1 Like

Short answer: no.
Long answer: Don't rely on the Flex Repeater to handle this for you; let your Views do the work with Message Handlers.

Setup:
Let the View being instanced accept a param (like index - this param is passed along free for all instances of the Flex Repeater without you needing to supply anything yourself).
17%20AM

on the ROOT node of the View, configure an onClick event to execute a Script Action with the following code:

system.perspective.sendMessage('ROOTCLICK', payload={'index': self.view.params.index}, scope='page')

Now go to the Flex Repeater, right-click the Flex Repeater, and select "Configure Scripts...".
Under Message Handlers, add a new handler with a message type of "ROOTCLICK", and supply the following code:

self.custom.selected = payload['index']

Now your Flex Repeater is aware of which instance was most recently clicked.

5 Likes

Hmmm, I am obviously doing something incorrect here.

  1. I created a custom parameter on the view that has the template repeater on it called index.
    image

  2. The instances on my flex repeater contains a index and a tag path:

  3. I added the following to the root container onClick Event:

system.perspective.sendMessage(‘ROOTCLICK’, payload={‘index’:self.view.params.index}, scope=‘page’)

  1. I created a new message handler called ‘ROOTCLICK’ on the template repeater with the following code (I am writing the results to a text tool so that I can see):

It does look like the Event is being called, but the value is not being passed to the View ‘index’ parameter.

Thoughts?

It is not writing to that parameter, it is writing to FlexRepeater.custom.selected.

See how you're modifying the Flex Repeater (please don't call it the Template Repeater - that's a Vision concept) and specifying self.custom.selected?

Ahhh I got it!!! Silly me, I put the code on the WRONG view!

It’s working, thank you!!!

1 Like

Are there any plans to pass certain parameters into Flex Repeater instances like the Perspective Table does? See my post here: Documentation on what is passed to table cell rendered as view - #4 by PGriffith

To my knowledge - aside from params you specify yourself - the only value passed along to each instance is the index of that instance.

1 Like

How I can take the index instance?

Add an index param on the view that you specify the path for on the Flex Repeater. Then you can use that param for whatever you need. For instance, I have a delete button on the view I’m repeating - when that button gets clicked, I send a message back to the repeater to remove the instance. Does that make sense @j.abrante?

Would you mind sharing your code of how you are removing the instance?

image
This is a simple component. When I press ‘x’ icon, it executes this onClick event:

msg = "del_instance_by_id"
system.perspective.sendMessage(msg, payload = {"index": self.view.params.index})

Then, on the Flex Repeater, I created a script (right-click, Configure Scripts…) and named it del_instance_by_id or whatever you want to call your message.

idx = payload["index"]    # receive payload from message
try:
    del self.props.instances[idx]
except:
    # handle exception (log, print, etc)

This works for me - there are probably many ways to do it, though.

3 Likes

Thank you!