Skip to content
This repository was archived by the owner on Jan 24, 2024. It is now read-only.

Commit e9a220c

Browse files
committed
Make multiple-select less “change-y”
1 parent aa30de8 commit e9a220c

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

multiple-select.js

+14-7
Original file line numberDiff line numberDiff line change
@@ -457,20 +457,19 @@
457457
return;
458458
}
459459

460-
that.updateSelectAll();
461-
that.update();
462-
that.updateOptGroupSelect();
463-
464460
if (that.options.singleSelect) {
465461
var clickedVal = $(this).val();
466462
that.$allControlItems.filter(function() {
467463
return $(this).val() !== clickedVal;
468464
}).each(function() {
469465
$(this).prop('checked', false);
470466
});
471-
that.update();
472467
}
473468

469+
that.updateSelectAll();
470+
that.update();
471+
that.updateOptGroupSelect();
472+
474473
that.options.onClick({
475474
label: $(this).parent().text(),
476475
value: $(this).val(),
@@ -571,8 +570,15 @@
571570
$span.prop('title', this.getSelects('text'));
572571
}
573572

573+
// trigger change on initial setting unless changeOnInit is set to false
574+
if (this.options.changeOnInit !== false) {
575+
this.$el.bind('ms-init-change', function() {
576+
$(this).trigger('change');
577+
});
578+
}
579+
574580
// set selects to select
575-
this.$el.val(this.getSelects()).trigger('change');
581+
this.$el.val(this.getSelects()).trigger('ms-init-change');
576582

577583
// add selected class to selected li
578584
this.$drop.find('li').not(this.$noResults).removeClass('selected').attr('hidden', false);
@@ -584,7 +590,7 @@
584590
});
585591

586592
// trigger <select> change event
587-
if (!isInit && isInit !== undefined) {
593+
if (!isInit) {
588594
this.$el.trigger('change');
589595
}
590596
},
@@ -829,6 +835,7 @@
829835
position: 'bottom',
830836
keepOpen: false,
831837
animate: 'none', // 'none', 'fade', 'slide'
838+
changeOnInit: false,
832839
displayValues: false,
833840
delimiter: ', ',
834841
addTitle: false,

0 commit comments

Comments
 (0)