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). Each instanced param now needs to have the index parameter passed
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.

2 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