Cannot unselect option element when preserveSelected is true
See original GitHub issueHi @truckingsim,
I am unable to unselect an option element in a multiple select when the preserveSelected
option is true. It only works after I do an ajax search.
The issue is reproducible: https://jsfiddle.net/a3ybhne4/5/
I have found the problem to be line 630
It works when I replace line 630
that.replaceOptions(that.cacheGet(that.plugin.query));
by
that.replaceOptions(that.selected);
I am not sure why that.plugin.query
is there in the first place and I am wondering if this change has any side effects…
Thanks for taking a look. EDIT: updated jsfiddle
Issue Analytics
- State:
- Created 7 years ago
- Reactions:4
- Comments:5 (3 by maintainers)
Top Results From Across the Web
bootstrap-select select/deselect all option click can't firing event?
How can I fire an event when product items select all/deselect all? I have tried with jquery click and change events like this:...
Read more >ajax-bootstrap-select - npm
Start using ajax-bootstrap-select in your project by running `npm i ... the select element must have the data-live-search="true" attribute.
Read more >ajax-bootstrap-select issue #84 - JSFiddle - Code Playground
cannot unselect option element when preserveSelected option is true ... <option value="TestOne" selected>Test One</option> ... liveSearch: true.
Read more >Ajax-Bootstrap-Select - Bountysource
multiple + preserveSelected + default <options> groups unselected options into ... Problem is I don't have a way to quickly check whether an...
Read more >Top 5 slate Code Examples - Snyk
To help you get started, we've selected a few slate examples, based on popular ... preserveSelection: true, ...options } // if (Object.keys(options).length) ...
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').selectpicker().ajaxSelectPicker()
$('.select-picker').trigger('change').data('AjaxBootstrapSelect').list.cache = {}
You can try from your updated fiddle https://jsfiddle.net/kinkongjeng/a3ybhne4/10/
The
that.cacheGet(that.plugin.query)
is our caching mechanism. It’s always used even if you have caching off. What cache off does is it loads the cached data and does an ajax request anyways. With caching on, if you’ve already done a search for that query (whatever the query is), it will grab the cached data this time won’t do an ajax request.What’s happening is we aren’t updating the cache on change. We set the cache value for no query on line 605 but after updating that.selected we never update the cache. So then it just keeps using the cached value.
So the fix is to update the cache. I think if we just add a
that.setCache
it will break preserveSelected so it will take some testing to make sure we don’t break that fixing this.If you feel you can make a PR with a fix for the cache I can test it to make sure it doesn’t break anything else. Otherwise it will probably be this weekend before I can get to this.