Get combobox Selected ID OnChange event

Get combobox Selected ID OnChange event

  

I'm having an issue similar to this post https://www.outsystems.com/forums/discussion/26488/pass-combobox-variable-to-onchange-screen-action-for-the-combo-box-for-sql-upda/.

I have a combobox with this settings:

Name: AccessList

Source Record List: GetApplicationFeatures.List

Source Attribute: ApplicationFeature.Lable

Selection Mode: Multiple

Selection Attribute: Selected

OnChange Destination: UpdateAccessList

                  FeatureId: AccessList.List.Current.ApplicationFeature.Id

FeatureId is the input parameter of action UpdateAccessList.

My problem is that UpdateAccessList.FeatureId always has the same value no matter what I select on the combobox. What am I doing wrong?


Thanks


Hi,

Is it possible to see a simple oml?

Afaik the onchange does not need an input parameter

Hi Tim Le

Just for the record, would you be talking about the LISTBOX widget in a Web Application?
I don't remember to see the property "Selection Mode" in ComboBox nor DropDownList (Mobile).

If you are talking about the ListBox, the value (boolean field of the Aggregate/Sql list record) you pass as value for the Selection Attribute will be used to say to you if the record is selected or not.

In other words, If you select an item in the ListBox, the Seelected Attribute (field)  of that record in the List Records you give to the ListBox will be set to true.

To know which records are selected, you need to iterate through this list and check this value (True is selected, False it isn't)

And so, no need to pass parameters to the OnChange action.

By the way, the CURRENT of the list you passed will not change when you select or unselect an item in the list (I think).

Cheers,
Eduardo Jauch

My bad. Sorry. It is a List Box. Attach is my OML

Tim Le,

The Current of the list will not be updated in the OnChange (as far as I know).You HAVE to iterate through the (ListBox) list to see which of the items are selected and which are not.

Cheers,
Eduardo Jauch 

Hi Ed,

As you can see there could be multiple values added/removed to the AccessList from time to time. So to be able to add/remove values from the AccessList, what would be the best approach? I was hoping to pass the selected/deselected ID so UpdateAccessList only needs to add/remove one record at a time. If I have to iterate through the list to find the ones selected to add and unselected to remove, would it be better to update this AccessList on form Submit?

Thanks for your help.

Solution

This would never work properly, as it is possible to select multiple items at the same time (holding shift).

Personally, I would use a pair of lists, passing the selected accesses to the right list, and keeping only the still available accesses in the left list. This is a very known pattern.

I have a component to do this   

https://www.outsystems.com/forge/component/1367/itemsselector/

If you prefer to keep a single list, using a ListBox, I don't see a different way of doing this than looking to each one and adding removing access accordingly the selection.

An alternative would be to use a List Records to show a list of Accesses, and style the access differently if they are select or not, using a link around the item to call the action (the List Records list current is updated to the item that is clicked. You can even include a "check box", as it is a list and accepts multiple fields.

Maybe another component in Forge can help (you will have to do a little research).

Cheers,
Eduardo Jauch

EDIT

My component needs some refactoring though, including upgrade for version 10 (while it will work anyway), and it uses the notify to the user to keep track of which elements are in the left or the right... (need to change this)

Solution

I'm using List Box along with Select2 component so users can only add one or remove one item at a time. That is why I am hoping to catch the ID of the item the users select or deselect and act upon it.

I will check out your ItemsSelector component to see if it works for me.

Thanks for your suggestion.

Hi Tim, 

If it do not works as you would like, I'll suggest the ListRecords approach, as it will do exactly what you want.

In any case, can you mark my first answer as correct, as it is the answer for your question? This helps keep the forum easier for everybody to use :)

Chhers,
Eduardo Jauch

Eduardo,

Can I achieve this scenario, using your component? 

Seems similar to the one on the above link, although I'm a bit stuck on how to implement it to fulfill my needs.

Hugo Nobre wrote:

Eduardo,

Can I achieve this scenario, using your component? 

Seems similar to the one on the above link, although I'm a bit stuck on how to implement it to fulfill my needs.

Hello Hugo,

While the component is not a good one (was my first), doing requests every time you select an item, yes it covers your scenario, as you can pass both lists, defining the left and right at the beginning.

When I have time, I'll implement some options to make it a little more performing, while keeping the possibility to send notifications on selections.

Cheers.