I can't find on select2 documentation a way to remove all the options in a select2 form. The old stckoverflow answers to this questions seem not to work since the new version (I'm using 4.0.3) has a different behavior
clear all select2 options
Asked Answered
Just
$('#id').empty().trigger("change");
Where '#id' is the jQuery selector for your select2 element.
Sorry, I sent it without finishing the last sentence. Is it ok now? –
Grizel
Sorry … don't seems to work on 4.1.0-RC1 maybe an RC issue –
Dispermous
Previous answer will delete all values, but in the official documentation it says:
$("#id").val(null).trigger("change");
It will only clear the selected items not to remove the options. –
Springhalt
© 2022 - 2024 — McMap. All rights reserved.