528
Views
4
Comments
Solved
[Select2] select2 multiple selection - get id
Select2
Web icon
Forge asset 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

2019-11-25 11-21-58
Ana Reis
 
MVP
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

2019-11-25 11-21-58
Ana Reis
 
MVP

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

2023-04-28 15-56-03
inesp

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?

2019-11-25 11-21-58
Ana Reis
 
MVP
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

2023-04-28 15-56-03
inesp

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!

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.