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.

Refresh Select2 without triggering change event

See original GitHub issue

In Select2 v4 documentation recommended to reset select by setting value to empty value and triggering event.

$('#id').val('').trigger('change')

But how to reset dropdown select to placeholder without triggering change event and replacing tons of dom elements? Something like

$('#id').select2('refresh')

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:13
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

80reactions
c-lee8commented, Feb 8, 2016

This appear to be an undocumented feature. I found the answer on stackoverflow, use 'change.select2'

$docInput.val(null).trigger('change.select2');

http://stackoverflow.com/q/17819709/359284#31856728

12reactions
kevin-browncommented, Feb 8, 2016

I might just document the change.select2 event as the recommended way to handle this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Clear select2 without triggering change event - Stack Overflow
I'm trying to clear that select2 without triggering a change event. Is this possible? To clear the select2 I'm using the following code:...
Read more >
Events | Select2 - The jQuery replacement for select boxes
Events. Select2 will trigger a few different events when different actions are taken using the component, allowing you to add custom hooks and...
Read more >
params object is not present when fire event using .trigger ...
Two things to mention here: - When you want to tell Select2 to update the state of the selected options, you should trigger...
Read more >
SCR19: Using an onchange event on a select element ... - W3C
Navigate to the trigger select element, navigate through the options but do not change the value. Check that the matching option values are...
Read more >
Options - Select2 - JeeSite
Select2 does not have a custom event (like select2:update ) that can be triggered other than change . You can rely on jQuery's...
Read more >

github_iconTop Related Medium Post

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