Other ways to trigger dropdown's onChange? It does not fire with 'set selected'
See original GitHub issueI have a simple setup like
$element.dropdown({
fullTextSearch: true,
onChange: function() {}
})
and then have an ajax at the end to pre-fill it
$.ajax({
// settings here
})
.done(
// iterate results and made <div class="item" data-value=value here>text here</div> with it
// and added it using .html()
$element
.dropdown('set selected', 'defaultValue')
)
onChange does not fire when doing that. Tried putting it insde setTimeout
and still not working.
BUT it does work when manually clicking or doing it from the console like $element.dropdown('set selected', 'otherValue')
I can see the defaultValue being selected but it’s just the event onChange
not firing.
tried doing .find()
and .trigger('change')
on the hidden input but no luck. even triggering change from the dropdown itself.
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
JavaScript onchange event won't fire if select option is ...
What I'm trying to do is to get the select element onchange event to fire regardless where the option is being changed from....
Read more >.change() | jQuery API Documentation
Attaches a change event to the select that gets the text for each selected option and writes them in the div. It then...
Read more >HTMLElement: change event - Web APIs | MDN
The change event is fired for <input> , <select> , and <textarea> elements when the user modifies the element's value.
Read more >Web dropdown list's onchange event cannot be triggered ...
I have dropdown list in my website. and an onchange event is binding to that dropdown list. I can use the 'select value'...
Read more >Bug(?): Dropdown OnChange behavior not as expected...
The OnChange property for dropdowns(with this collection as its items property or default) also set global variables, I do this so that screens ......
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
Hi @xxRockOnxx, when it’s
done()
and you populated it with options, try executing the$el.dropdown('refresh')
before selecting the default value, and please let me know if it helped:I think I found the cause of the problem in case other might experience the same issue as me.
There was a
value
attribute on theinput
itself. Might work if the value is not the same as the one you put inset selected
. Doingset selected
with the same value as the current one will not trigger a change.