Commit 958a7e2d authored by David Stutz's avatar David Stutz

Merge pull request #160 from sathyamoorthi/select-deselect

select and deselect changed to accept array.
parents 5f12a94e e726973f
......@@ -446,45 +446,61 @@
},
// Select an option by its value.
select: function(value) {
var $option = $('option', this.$select).filter(function() {
return $(this).val() == value;
});
var $checkbox = $('.multiselect-container li input', this.$container).filter(function() {
return $(this).val() == value;
});
if (this.options.selectedClass) {
$checkbox.parents('li').addClass(this.options.selectedClass);
select: function(selectValues) {
if(selectValues && !$.isArray(selectValues)) {
selectValues = [selectValues];
}
$checkbox.prop('checked', true);
for(var i = 0; i < selectValues.length; i ++) {
var value = selectValues[i];
$option.attr('selected', 'selected').prop('selected', true);
var $option = $('option', this.$select).filter(function() {
return $(this).val() == value;
});
var $checkbox = $('.multiselect-container li input', this.$container).filter(function() {
return $(this).val() == value;
});
if (this.options.selectedClass) {
$checkbox.parents('li').addClass(this.options.selectedClass);
}
$checkbox.prop('checked', true);
$option.attr('selected', 'selected').prop('selected', true);
this.options.onChange($option, true);
}
this.updateButtonText();
this.options.onChange($option, true);
},
// Deselect an option by its value.
deselect: function(value) {
var $option = $('option', this.$select).filter(function() {
return $(this).val() == value;
});
var $checkbox = $('.multiselect-container li input', this.$container).filter(function() {
return $(this).val() == value;
});
if (this.options.selectedClass) {
$checkbox.parents('li').removeClass(this.options.selectedClass);
deselect: function(deselectValues) {
if(deselectValues && !$.isArray(deselectValues)) {
deselectValues = [deselectValues];
}
$checkbox.prop('checked', false);
for(var i = 0; i < deselectValues.length; i ++) {
var value = deselectValues[i];
var $option = $('option', this.$select).filter(function() {
return $(this).val() == value;
});
var $checkbox = $('.multiselect-container li input', this.$container).filter(function() {
return $(this).val() == value;
});
if (this.options.selectedClass) {
$checkbox.parents('li').removeClass(this.options.selectedClass);
}
$checkbox.prop('checked', false);
$option.removeAttr('selected').prop('selected', false);
$option.removeAttr('selected').prop('selected', false);
this.options.onChange($option, false);
}
this.updateButtonText();
this.options.onChange($option, false);
},
// Rebuild the whole dropdown menu.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment