bootstrap-multiselect
bootstrap-multiselect copied to clipboard
Issue with deselectAll and radio multiselect (multiple = false)
Hi,
When I try to clearSelection my multiselect the label of the multiselect is properly reset but when I open my multiselect the previous radio button chosen is still checked. If I am not wrong I think it probably comes from the deselectAll function where only the checkbox case is handled.
I have added a:
var type = this.options.multiple === true ? "checkbox" : "radio"; And I use this variable inside the js selectors (ie: $("li input[type='"+type+"']:enabled" ) and it seems to work. It's important for me because I trigger something on the change event :). If a value is already selected we can't fire the change event except if we select an other option and come back later.
Might be related to #129! I will check this, however, as stated in #129 and as I remember, a part of this problem is also due to browser behavior.
If the problem is the browser behaviour, may be it could at least select the first radio option by default when we deselectAll ? In this case it would correspond to the default state of a select on all browser like if nothing had been selected first.
I had to do a refresh: $('#myMS').multiselect('refresh'); to get rid of the previously selected item.
+1 In our case, we have several dropdowns, and 1 button that clears them all. Unfortunately, after clearing (using 'clearSelection()') them it's not possible to re-select the previous selection (unless you select something else first).
To fix this, I've swapped out the 'change' events for 'click' events. That fixes the issue, and also fixes a related bug where the dropdown won't close if you click on an option that's already selected.
Is there a reason why the 'change' event is used instead of the 'click' event? I don't see any downside to switching to 'click'.
Not sure whether the click
event screws up keyboard support. Might check it first before switching.
@zephyx did your provided solution ever got into the source code and released as I am facing the same issue in 2020 while using the plugin.
I used various combinations of .val(''), .multiselect('resfresh'), .multiselect('deselectAll', false), and .multiselect('updateButtonText') as suggested in docs and many issues and although a specific combination resolves the issue at the browser side of clearing the selected radio button however when the values is submitted back to the server, it has the last "default / selected" option as selected.
What are the recommendations?
Same issue here.
unselectAll
doesn't work. Unselection for all options works only using the following lines:
$('.myselect').val('');
$('.myselect').multiselect('refresh');