Check if a repeater item is selected

How can I check to see if a single repeater item is selected?

My objective is to show an element IF the repeater item is selected onClick. ELSE it needs to be hidden.

The repeater item is set to toggle and having difficulty show/hiding the element when only one of the repeater items is selected. What condition could I use to build the logic to show that element ONLY when the selected repeater item is selected (or hidden if not selected)?

A few questions… What exactly do you mean by 'if a single repeater item is selected" --an operational definition would help. Posting your .rp file here would be much better. Specifically, what is a “repeater item”? Checkbox? Button? The repeater row? The entire repeater widget? What is the importance of “a single item” versus more “items” which might be selected? Is it the case that your “element” should be hidden if less than 1 or greater than 1 “repeater items” are selected? Or, would it be shown if at least one repeater item is selected? For that matter, can more than one repeater item be selected at once?

What do you mean by “show an element” --what do you mean, exactly, by “an element”? A specific widget? Is the “element” inside or outside the repeater?

In general, you could track and control this in the repeater’s OnItemLoad event. The first Case could be a condition like, If [[Item.IsFirst]] is equal to "true" set OnLoadVariable equal to 0 (or use some other global variable or a hidden text widget) which would initialize your count of selected items/rows. Then you could have a following Case with a condition like, If [[Item.SelectionState]] is equal to "true" set OnLoadVariable to [[OnLoadVariable + 1]] and Set selected of MyRepeaterItem to "true" --where “SelectionState” is a column in your repeater.

Once the entire repeater is loaded, you’ll have a count of how many repeater items are selected. You can then use the repeater’s OnLoad event to handle what to do based on the value of your counter (OnLoadVariable in this example.) So, something like, If value of OnLoadVariable is equal to 1 show MyElement, Else hide MyElement.

Clicking on the repeater item would Update This Row to set the value of SelectionState to selected state of This. If you do this instead of just toggling the selection state then your repeater dataset can be used to track, control, and count how many items are selected.

My apologies for being so vague. Essentially, I want to show something if a repeater row is selected. Otherwise, don’t show it.

I’ve included an example.

In this example, when a ‘Ticket List Item’ is selected I want to show the ‘List Item Selector’. Only one ‘Ticket List Item’ can be selected at a time and so the same would apply for the ‘List Item Selector’

Please look at the file and let me know if there is anything else I can help explain better.

example.rp (64.0 KB)

Thank you for posting the .rp file, totally helps me understand what’s going on.

A few little tweaks and this works. I duplicated your page in this updated file with these changes:

  • I moved the “List Item Selector” to the left so it can actually appear in the dynamic panel that contains the repeater. (The repeater will grow to show it but the dynamic panel is set to a fixed width which is too narrow to show the list selector.)
  • I made the “List Item Selector” selectable and shown when selected by styling its selection state to 100% opacity and its normal state to 0% opacity. This is mostly just a different way to show/hide a widget. I could have kept your “List Item Selector” as is and add a Show/Hide action to the OnClick event for the “Ticket List Item” group. But, since it was already in the “Ticket List Item” group and the selection state for the group is toggled when clicked, the selection state of “List Item Selector” is already toggled, so this is an easy way to take advantage of that.
  • To ensure that only one “List Item Selector” is selected at once, I assigned it a selection group, just like you did for the “Ticket List Item” group.

example.rp (91.9 KB)

3 Likes

That is exactly what I was looking for. Thank you so much for your help. I will look into how you did this as it works perfectly.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.