Pop-up window
I am using the multi selector popup.
Please see jsfiddle example
$(function () { $('#lstStates').multiselect({ }); });
Once you select states, it shows TEXT and concat value with comma like: New Jersey, New York, Ohio
But I want VALUE to choose ITEM like: NJ, NY, OH
+3
Maddy
source
to share
2 answers
You can use the option buttonText
for the multi selector.
http://jsfiddle.net/ejqngpn5/
$('#lstStates').multiselect({
buttonText: function(options, select) {
console.log(select[0].length);
if (options.length === 0) {
return 'None selected';
}
if (options.length === select[0].length) {
return 'All selected ('+select[0].length+')';
}
else if (options.length >= 4) {
return options.length + ' selected';
}
else {
var labels = [];
console.log(options);
options.each(function() {
labels.push($(this).val());
});
return labels.join(', ') + '';
}
}
});
+4
Ersin basaran
source
to share
Use the buttonText parameter for the multiSelect plugin. Parameters Parameters provide you with all the options that you choose. Then format your buttonText value as you want.
Script
$(function () {
$('#lstStates').multiselect({
buttonText: function(options){
if (options.length === 0) {
return 'No option selected ...';
}
var labels = [];
options.each(function() {
if ($(this).attr('value') !== undefined) {
labels.push($(this).attr('value'));
}
});
return labels.join(', ');
}
});
});
Take a look at the fiddle: http://jsfiddle.net/74b5pkpv/
0
Mahedi sabuj
source
to share