How to get selected index of Custom Collection?

The Custom Collection (collectionView) has selectedIndex and selectedItem properties, but neither seem to update when I select/interact with the different items in the collection. Is there a trick to this?

I found this old thread saying the same thing, which was supposedly fixed, yet I'm having the same issue still. Perhaps I've overlooked something.

Note - listCollection and cardCollection components also have the selectedIndex and selectedItem properties, and they do update correctly as you interact with the collection items.

My current use case needs to include a segmentedControl and a textArea for each item in the collection so that rules out using the listCollection and has me using Custom Collection (collectionView). I can get the collectionView to display the way I need but can't seem to access which item is clicked/selected.

1 Like

Hey @Bman040! Took a look at this and saw that those properties only populated when there was a press event handler attached to the collectionView. I'll submit a report to our eng team, but thought that adding an event handler might be a sufficient workaround for you in the interim.

The event handler doesn't actually have to do anything (unless of course you want it to), so you won't get any unintended consequences in the app. I have it Run Script but left the script empty.

CleanShot 2024-04-05 at 10.15.17

CleanShot 2024-04-05 at 10.15.31

Let me know if that helps!

Hi Joe, thanks for the reply. This workaround doesn't seem to help my use case. I was able to re-create getting the selectedItem/Index to update by adding a press event handler as you suggested, but the problem is that doesn't work if you click on any child components. In each collectionView item I have several components: a segmentedControl, a textArea and an imageInput. When I interact with any of those child components it does not update the state of the collectionView itself. If I click (press) on the actual collectionView item, (meaning the background white space behind the child components), then yes it updates the state. But what good is a collectionView with nothing in it. So real world use case it doesn't really help.

1 Like

Ahhh, yep you are correct. It was working for me, but I wasn't clicking directly into the text component. Sorry that workaround didn't prove useful! I'll update the bug report, and keep you posted here as I hear anything on it's status.