question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Dropdown] `set selected` trigger multiple times `onChange` callback when selecting multiple values

See original GitHub issue

Bug Report

Steps to reproduce

  1. Create a multiple selection dropdown
  2. Use the set selected behavior to add at least two selected values
  3. !?

Expected result

onChange is fired once

Actual result

onChange is fired multiple times

Testcase

https://jsfiddle.net/kqbfpwm6/1/

Related SUI issues

Semantic-Org/Semantic-UI#4913 Semantic-Org/Semantic-UI#4691

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
cupcakedreamcommented, May 15, 2020

Would love to see this change made +1

0reactions
ardamose123commented, Aug 9, 2020

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, the onChange 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 trigger onChange 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 the onChange(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 existing onChange.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found