Deselecting doesn't work after adding the options to <select> on page load
See original GitHub issueHi all,
I am experiencing a wrong behavior. On page load I add the options to the <select>
element as selected options:
<select id="filter_company" class="selectpicker" multiple title="..." data-live-search="true">
<option value='company1' selected>Company 1</option>
<option value='company2' selected>Company 2</option>
<option value='company3' selected>Company 3</option>
</select>
In JS I initialize the ajaxSelectPicker
as required with all necessary options use the trigger:
$('#filter_company').trigger('change');
However, deselecting doesn’t work until I write a keyword in the search. Instead, on deselecting the items change positions but stay selected.
Does anyone else experience that and how could we solve this?
Cheers, Andrius
Issue Analytics
- State:
- Created 7 years ago
- Reactions:6
- Comments:14
Top Results From Across the Web
Can't select option after deselecting it with JQuery or in UI
When I was using old multi-select JQuery plugin, I find out that I can't select previously deselected options. Actually, I can see that...
Read more >Next button re-enabled on page load and unselect
When I inspected the Qualtrics javascript, I have noticed that upon page load and selecting/de-selecting any option, there's a series of ...
Read more >Cannot select multiple objects in AutoCAD
On the Cursor & Selection tab, clear the Use Shift key to add to selection option. User-added image; Choose OK to close the...
Read more >How do you programmatically deselect an item after a ... - Telerik
When the app loads nothing is selected. If you select the item in the drop down and then click the "clear selection" button...
Read more >Printing complex PDF document using Acrobat - Adobe Support
Re-create the page or object that is causing the problem. ... Select any PostScript options that aren't selected and deselect any options ......
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
I have fixed this issue by clean the cache object with this code
// Use after init select picker
$('#select-picker').trigger('change').data('AjaxBootstrapSelect').list.cache = {}
You can try from this fiddle https://jsfiddle.net/kinkongjeng/2o7j08kb/
I found out that deselecting only works if the options are selected by JS on page load instead of marking them as
selected
when rendering HTML:However, it’s still not ideal since the deselected options are not moved out from the “Currently Selected”
optgroup
, but that I can live with. Also, on deselecting the options are sorted depending on option “preserveSelectedPosition” (before/after) and it can be a little confusing for the user. If the deselected options were moved out from the “Currently Selected”optgroup
, it wouldn’t be confusing.If anyone knows how to make it work correctly, please let me know.