I am using the Bootstrap Multiselect drop-down. Instead of the number of items shown when hit "Select All" option, can we show the "All Selected" text?
If someone hit this question in the future , solution is change the
{ nonSelectedText: 'None selected' }
assign a global variable to this text change it through JavaScript.
value resides in bootstrap-multiselect.js file.
noneSelectedText
for each new multiselect object, if you have multiple. Thanks! –
Velvetvelveteen You can change "Label" (of bootstrap multiselect) text for all 4 cases "none selected", "n selected", "All" Selected or "selected values" as follows:
JQuery
$('#level').multiselect({
includeSelectAllOption: true,
maxHeight: 150,
buttonWidth: 150,
numberDisplayed: 2,
nSelectedText: 'selected',
nonSelectedText: 'None selected',
buttonText: function(options, select) {
var numberOfOptions = $(this).children('option').length;
if (options.length === 0) {
return nonSelectedText + ' <b class="caret"></b>';
}
else{
if (options.length > numberDisplayed) {
if(options.length === numberOfOptions){
return ' All Selected' + ' <b class="caret"></b>';
}
return options.length + ' ' + nSelectedText + ' <b class="caret"></b>';
}else {
var selected = '';
options.each(function() {
var label = ($(this).attr('label') !== undefined) ?
$(this).attr('label'):$(this).html();
selected += label + ', ';
});
return selected.substr(0, selected.length - 2) + ' <b class="caret"></b>';
}
}
}
});
HTML
<select multiple="multiple" id="level">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
It works for me. Have fun!
Use init obj options.
$("#services").multiselect({
nonSelectedText:'Services'
});
This option worked for me.
nonSelectedText
–
Di use data-placeholder
<select data-placeholder="Month">
This work for me.
Following the official documentation:
allSelectedText
is the text displayed if all options are selected. You can disable displaying theallSelectedText
by setting it to false.
use option
{
...
allSelectedText: false,
...
}
Philip's answer worked for me, but just making it a bit more complete, it should be called upon document ready. So the solution for me, including setting multiple lists was:
$(document).ready(function() {
$("#bedrooms").multiselect({
nonSelectedText:'Bedrooms'
});
$("#bathrooms").multiselect({
nonSelectedText:'Bathrooms'
});
$("#garages").multiselect({
nonSelectedText:'Garages'
});
$("#livingareas").multiselect({
nonSelectedText:'Living Areas'
});
});
I changed 3rd button's (hint of button : Multiselect with a 'Select all' option) id to test. It works but you need to add id to button from developer tools (Chrome / Firefox add F12) first.
$('#test+ul>li').change(function(){
$('#test').text($('#test').attr('title'));
});
You can test it after you added the id. Please use jsfiddle.net after that. You may find help more quickly.
© 2022 - 2024 — McMap. All rights reserved.