Reputation: 171
I want to disable the Deselect All
button. I want to keep the Select All
button too.
Here's my select:
<select id="typeCheckboxSelect" class="selectpicker" name="typeSelector[]" multiple="multiple">
<option class='typeCheckbox' type='checkbox' value='test1'>Test One</option>
<option class='typeCheckbox' type='checkbox' value='test2'>Test Two</option>
<option class='typeCheckbox' type='checkbox' value='test3'>Test Three</option>
</select>
Upvotes: 0
Views: 3932
Reputation: 1635
In the onSelectAll callback, you can hide or disable the button, depending on your selections.
You will also probably want to include logic to re-enable the button given certain situations, but I do not know when those situations would be for you. Note that this onSelectAll callback will occur if you manually select every entry.
html:
<div id="selectContainer">
<select id="typeCheckboxSelect" multiple="multiple">
<option value='test1'>Test One</option>
<option value='test2'>Test Two</option>
<option value='test3'>Test Three</option>
</select>
</div>
MultiSelect Initialization:
$("#typeCheckboxSelect").multiselect({
includeSelectAllOption: true,
onSelectAll: function() {
$("#selectContainer .multiselect-container input[value='multiselect-all']").prop('disabled', true);
}
});
This will simply disable the button. If you want to re-enable it, you would call the below code in whatever handler you want.
$("#selectContainer .multiselect-container input[value='multiselect-all']").prop('disabled', false);
I have created a fiddle demonstrating it here.
Upvotes: 2
Reputation: 934
You can use this fiddle
$('#select_all').click(function() {
$('#typeCheckboxSelect option').prop('selected', true);
$("#de_select_all").prop('disabled', false);
});
$('#de_select_all').click(function() {
$('#typeCheckboxSelect option').prop('selected', false);
$(this).prop('disabled', true);
});
$(document).on('change', '#typeCheckboxSelect', function() {
$("#de_select_all").prop('disabled', false);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select id="typeCheckboxSelect" class="selectpicker" name="typeSelector[]" multiple="multiple">
<option class='typeCheckbox' type='checkbox' value='test1'>Test One</option>
<option class='typeCheckbox' type='checkbox' value='test2'>Test Two</option>
<option class='typeCheckbox' type='checkbox' value='test3'>Test Three</option>
</select>
<br>
<input type="button" id="select_all" name="select_all" value="Select All">
<br>
<input type="button" id="de_select_all" name="de_select_all" value="De Select All">
Upvotes: 2