I'm using Bootstrap multiselect and I would like to add an option to uncheck all selected options. Please provide me with a solution for the same. Thanks for any help :)
Try this
$("option:selected").prop("selected", false)
$('#multi-select-dropdown').multiselect("deselectAll", false).multiselect("refresh");
–
Euniceeunuch You can use .multiselect('refresh')
method as mentioned in the bootstrap-multiselect
documentation here.
So, add an HTML button / icon next to the multi-select select list and then use the below code:
$("#reset_client").click(function(){
$('option', $('#select_client')).each(function(element) {
$(this).removeAttr('selected').prop('selected', false);
});
$("#select_client").multiselect('refresh');
});
<select name="clients[]" multiple="multiple" id="select_client" style="display: none;">
<option value="multiselect-all"> Select all</option>
<option value="1">Client 1</option>
<option value="2">Client 2</option>
<option value="3">Client 3</option>
<option selected="selected" value="4">Client 4</option>
<option selected="selected" value="5">Client 5</option>
<option value="6">Client 6</option>
<option selected="selected" value="7">Client 7</option>
<option value="8">Client 8</option>
</select>
<input type="button" value="Reset" name="reset_clients" id="reset_client" class="reset_button" title="Clear Selection">
Use below code to deselect all select item in multiselect bootstrap dropdown
$("#ddlMultiSelectId").multiselect('clearSelection');
You can include a "select all" button, pushing that twice would "unselect all". To do this add this option:
includeSelectAllOption:true
This will deslect all for a bootstrap multiselect based on a select element.
function multiselect_deselectAll($el) { $('option', $el).each(function(element) { $el.multiselect('deselect', $(this).val()); }); } $('.multiselect').each(function() { var select = $(this); multiselect_deselectAll(select); });
You could add an option by hand that says "Select all" and then when it's pressed call the reset function.
See: https://github.com/davidstutz/bootstrap-multiselect/issues/271
You can do this with the "deselectAll" method.
$("select.multiselect").multiselect("deselectAll", false);
It is important that you tell jQuery to target your "select's" only, otherwise it will fail. This is because the plugin adds something else with the same class name.
@L_7337 - This is not a duplicate of the post you link to. This post is about how to deselect all options, if you use Bootstrap Multiselect
The other post, is how to deselect, from a normal multiselect option.
Best regards Rasmus
If you have the below multi-select:
<div class="form-group">
<label>Choose Skills</label>
<select id="DDL" name="selValue" class="selectpicker form-control" multiple>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
</div>
Then you can use the below jQuery to deselect all option on a click of a button:
$('#DDL').selectpicker("deselectAll", true).selectpicker("refresh");
Try this:
$("#select_id option:selected").removeAttr("selected");
The issue was fixed in a gitlab fork here
it says:
Fixed trigger onSelectAll when deselecting Select All
Alternatively we can wait while issue #752 will be resolved. It was raised only one month ago.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class = "container">
<div class="modal show" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button class="close" type="button" data-dismiss="modal">×</button>
<nav class="navbar navbar-default">
<div>
<ul class="nav navbar-nav">
<li class="active"><a href="#">Channel(s)</a></li>
<li><a href="#">Collaborator(s)</a></li>
</ul>
</div>
</nav>
</div>
<div class="modal-body">
<form> <div class="form-check row">
<label class="col-sm-2 form-check-label" for="ListeningProject">Listening Project</label>
<div class="col-sm-10">
<input class="form-check-input" id="ListeningProject" value="" type="checkbox" />
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 form-check-label" for="AccountName">Select:</label>
<div class="col-sm-10">
<select class="form-control" id="AccountName" multiple="" required="">
<option>A Company</option>
<option>B Copany</option>
<option>C Company</option>
<option>D Company</option>
</select>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<script>
$("#ListeningProject").change(function(){ //"select all" change
var status = this.checked; // "select all" checked status
$('#AccountName option').prop('selected', status);
});
</script>
</body>
</html>
You can do like this, it works for me:
$('#dropdownID').val([]).multiselect('refresh')
Try this
$("option:selected").prop("selected", false)
$('#multi-select-dropdown').multiselect("deselectAll", false).multiselect("refresh");
–
Euniceeunuch © 2022 - 2024 — McMap. All rights reserved.