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.

Deselecting doesn't work after adding the options to <select> on page load

See original GitHub issue

Hi 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:closed
  • Created 7 years ago
  • Reactions:6
  • Comments:14

github_iconTop GitHub Comments

3reactions
jengjengcommented, May 9, 2017

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/

3reactions
andrius-senuliscommented, Oct 17, 2016

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:

$('#filter_company').val(selected_companies).trigger('change').selectpicker('refresh');

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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