Skip to content

Commit fbe6dba

Browse files
committed
Fixes #656
Also fixes #590 by giving the option of changing the separator value.
1 parent 8a3f392 commit fbe6dba

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/jquery.multiselect.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
multiple: true,
4444
position: {},
4545
appendTo: "body",
46-
menuWidth:null
46+
menuWidth:null,
47+
selectedListSeparator: ', '
4748
},
4849

4950
_create: function() {
@@ -242,7 +243,7 @@
242243
if($.isFunction(o.selectedText)) {
243244
value = o.selectedText.call(this, numChecked, $inputs.length, $checked.get());
244245
} else if(/\d/.test(o.selectedList) && o.selectedList > 0 && numChecked <= o.selectedList) {
245-
value = $checked.map(function() { return $(this).next().text(); }).get().join(', ');
246+
value = $checked.map(function() { return $(this).next().text(); }).get().join(o.selectedListSeparator);
246247
} else {
247248
value = o.selectedText.replace('#', numChecked).replace('#', $inputs.length);
248249
}
@@ -754,6 +755,11 @@
754755
break;
755756
case 'position':
756757
this.position();
758+
break;
759+
case 'selectedListSeparator':
760+
this.options[key] = value;
761+
this.button[0].defaultValue = this.update();
762+
break;
757763
}
758764

759765
$.Widget.prototype._setOption.apply(this, arguments);

tests/unit/options.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,4 +347,19 @@
347347
equals(menu().find(".ui-multiselect-close").find("."+icon).length, 1);
348348
el.multiselect("destroy");
349349
});
350+
test("selectedListSeparator", function(){
351+
expect(3);
352+
el = $("select").multiselect({ selectedListSeparator: "<br/>", selectedList: 15 });
353+
el.multiselect("checkAll");
354+
var text = $(button()).text();
355+
var matched = [];
356+
equals(text.indexOf(","), -1, "There are no commas in the button text");
357+
matched = text.match(/\<br\/\>/g);
358+
equals(matched.length, 8, "The 9 selected values are joined by <br> tags");
359+
el.multiselect("option", "selectedListSeparator", ", ");
360+
text = $(button()).text();
361+
matched = text.match(/\,/g)
362+
equals(matched.length, 8, "The 9 selected values are joined by commas again after calling the option method");
363+
el.multiselect("destroy");
364+
});
350365
})(jQuery);

0 commit comments

Comments
 (0)