jeudi 15 janvier 2015

Dynamic "noneSelectedText" for multiselect jquery box

I'm trying to get a dynamic field for a multiselect checkbox section of a page - specifically the noneSelectedText. Here is the html:



<select name="set_town[]" class="my_select set_town" multiple="multiple" data-selected-text="Select Town">


I found jQuery UI MultiSelect Widget - noneSelectedText for more than one select tag , but I can't get the included code sample to work. I've used both .data() and .attr() to no avail. The following works, but the "Select Town" content is not dynamic, and I have several checkbox fields to populate (all different).



$('select[multiple="multiple"]').multiselect({
noneSelectedText: 'Select Town',
header: false,
selectedText: function(numChecked, numTotal, checkedItems){
return numChecked + ' of ' + numTotal + ' checked';
}


It's not THAT many fields, though, so I'm willing to hardcode the values if I can get a conditional set up properly, but I think I have my syntax wrong with that, too...



$('select[multiple="multiple"]').multiselect({
if ( $(".set_town" ) ) {
noneSelectedText: 'Select Town',
}
header: false,
selectedText: function(numChecked, numTotal, checkedItems){
return numChecked + ' of ' + numTotal + ' checked';
}




Aucun commentaire:

Enregistrer un commentaire