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 @@ ...@@ -446,45 +446,61 @@
}, },
// Select an option by its value. // Select an option by its value.
select: function(value) { select: function(selectValues) {
var $option = $('option', this.$select).filter(function() { if(selectValues && !$.isArray(selectValues)) {
return $(this).val() == value; selectValues = [selectValues];
});
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); 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.updateButtonText();
this.options.onChange($option, true);
}, },
// Deselect an option by its value. // Deselect an option by its value.
deselect: function(value) { deselect: function(deselectValues) {
var $option = $('option', this.$select).filter(function() { if(deselectValues && !$.isArray(deselectValues)) {
return $(this).val() == value; deselectValues = [deselectValues];
});
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); 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.updateButtonText();
this.options.onChange($option, false);
}, },
// Rebuild the whole dropdown menu. // 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