[Dropdown] `set selected` trigger multiple times `onChange` callback when selecting multiple values
See original GitHub issueBug Report
Steps to reproduce
- Create a multiple selection dropdown
- Use the
set selected
behavior to add at least two selected values - !?
Expected result
onChange
is fired once
Actual result
onChange
is fired multiple times
Testcase
https://jsfiddle.net/kqbfpwm6/1/
Related SUI issues
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (7 by maintainers)
Top Results From Across the Web
Trigger change after items are selected in a multiple select
I thought of using setTimeout and saving 500ms after the onChange event is triggered, but I don't know if this is the best...
Read more >Events | Select2 - The jQuery replacement for select boxes
Select2 will trigger a few different events when different actions are taken using the component, allowing you to add custom hooks and perform...
Read more >.change() | jQuery API Documentation
A function to execute each time the event is triggered. ... The change event is sent to an element when its value changes....
Read more >SCR19: Using an onchange event on a select element ...
This technique will not cause a change of context. When there are one or more select elements on the Web page, an onchange...
Read more >HTML onchange Event Attribute
Execute a JavaScript when a user changes the selected option of a <select> element: <select onchange="myFunction()">. Try it Yourself ». More "Try it ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Would love to see this change made +1
I’d like to tackle this. However, what I read in the discussion and how
onChange
works currently look different.Currently, after using
set selected
, theonChange
callback is fired once for each provided value that was not previously selected. The callback receives 3 parameters,value
,text
and$choice
, as per the documentation in https://fomantic-ui.com/modules/dropdown.html#/settings.The fix would be to have a configuration setting for
.dropdown({ ... })
to triggeronChange
either once per affected option or just once per “batch operation” (set selected
,remove selected
). This setting will affect the data sent through the second parameter to theonChange(value, text, $choice)
callback.Am I on the right track here?
Another possible solution would be to have a completely new callback function (
onUpdate
or similar name) that provides the callback with the values and texts/labels as arrays and fires only once per batch operation. This shouldn’t break any existing code in the end; people who want to have this new behavior would use the new callback instead of the existingonChange
.