Bootstrap multiselect (update) is not working properly

I use the multiselect box block. When the user selects parameters in the multi selector, it displays correctly. But there is a reset option for previously selected parameters. When the user presses the reset button, style=display:none automatically adds a drop-down list button, and the drop-down list becomes invisible.

This is my code.

 $("#button").click(function () { $('option', $('.multiselect')).each(function (element) { $(this).removeAttr('selected').prop('selected', false); }); $('.multiselect').multiselect('refresh'); }); 
+6
source share
4 answers

Other useful options:

  • $('Id').multiselect('refresh'); - Updates multi-selection based on selected selection options.

  • $('Id').multiselect('destroy'); - Unbinds the entire plugin.

  • buildFilter : Creates a filter.

  • buildSelectAll : Create selct all.Checks if everything is already created.

  • $('Id').multiselect('select', ['1', '2', '4']); - select all setpoint parameters.

  • clearSelection : clears all selected items.

  • $('Id').multiselect('deselect', ['1', '2', '4']); - cancels the selection of all parameters of the set values.

  • $('Id').multiselect('selectAll', true); - selection of all allowed and visible parameters.

  • $('Id').multiselect('deselectAll', true); - Deselect all options.

  • $('Id').multiselect('rebuild'); - rebuild the plugin.

  • $('Id').multiselect('enable'); - Enable multi selector.

  • $('Id').multiselect('disable'); - turn off the multi selector.

  • hasSelectAll : checks for the Select All check box.

  • updateSelectAll : updates the "Select All" check box based on the currently displayed and selected check boxes.

  • $('Id').multiselect('updateButtonText'); - Update the button text and its name based on the currently selected options.

  • getSelected() : Get all selected parameters.

  • getOptionByValue() : Gets the selection option by its value.

  • $('Id').multiselect('dataprovider', options); - the provided data will be used to create a drop-down list.

visit bootstrap-multiselect for more details

+27
source

Bootstrap Multiselect error if you just target the class this way.

 $(".multiselect").multiselect("refresh"); 

This is because there is something else in the plugin that has the "multiselect" class. You must tell him that this is only the one you want to configure.

The following worked for me.

 $("select.multiselect").multiselect("refresh"); 

The same applies to the deselect method.

 $("select.multiselect").multiselect("deselectAll", false); 
+4
source

Have a look at this documentation: http://davidstutz.imtqy.com/bootstrap-multiselect/

To deselect an option, use this

 $('.multiselect').multiselect('deselect', value) 

Then call the update method

 $('.multiselect').multiselect('refresh'); 
+2
source

My approach is to destroy multi-selection and then reinitialize it. It worked for me. Try:

  function initMultiSelect(){ $('#yourMultiselectId').multiselect({ includeSelectAllOption: true, selectAllValue: 'select-all-value' }); } $('#button').click(function(e){ e.preventDefault(); $('#yourMultiselectId').multiselect('destroy'); initMultiSelect(); }); 
+1
source

Source: https://habr.com/ru/post/975036/


All Articles