[Select2] select2 multiple selection - get id

[Select2] select2 multiple selection - get id

  
Forge Component
(2)
Published on 2015-06-29 by Eduardo Luís
2 votes
Published on 2015-06-29 by Eduardo Luís

I'm using the select2 widget in a multiple selection scenario. However, I need to be able to access the id of the clicked/selected option and I'm not having any success... Does anyone know how can I do this?

Thanks in advance

Hi Maria,

The multiple selection scenario uses the List Box widget. The configuration of this widget requires that you have a list of possible values and a IsSelected for each element of that list to identify the ones that are were selected/clicked. So you need to iterate over the source list to check which elements are selected.

Ana Reis

Hi Ana. I know how it is used, but the thing is that when I want to process the list in an 'OnChange' screen action, I can't access the list. In the dedugger the screen action "says" that the list is empty. However, I discovered that if I pass the list as input parameter of a server action, the list is not empty and has the updated values.

Is there any reason for this behavior?

Solution

Hi Maria,

You need to actually use your selected list on the "OnChange" action to see the list with values. If you are not using the list on the action the platform optimizes the code and does not fill in the values so when you check the list in debug it seams to be empty.

If you do, for instance, a for each on the OnChange to iterate over the widget.list the records will appear. 

Ana Reis

Solution

Ana,

thanks for your help. In fact I forgot the optimization detail and therefore the list always appeared as empty.

Thanks for your quick answers and help!