Checkbox groups now return an array of booleans

This commit is contained in:
Keegan
2016-06-15 14:20:35 -07:00
parent cabee3ae0b
commit a0335be710
7 changed files with 44 additions and 59 deletions
+1 -2
View File
@@ -8,7 +8,6 @@ module.exports = {
defaults: {
label: '',
options: [],
description: '',
attributes: {}
description: ''
}
};
+12 -9
View File
@@ -133,24 +133,27 @@ module.exports = {
checkboxgroup: {
get: function() {
var result = [];
this.$element.select('input:checked').each(function(item) {
result.push(item.value);
this.$element.select('input').each(function(item) {
result.push(!!item.checked);
});
return result;
},
set: function(values) {
var self = this;
values = values || [];
values = Array.isArray(values) ? values : [];
while (values.length < this.get().length) {
values.push(false);
}
if (_.equals(this.get(), values)) { return this; }
self.$element.select('input').set('checked', false);
self.$element.select('input')
.set('checked', false)
.each(function(item, index) {
item.checked = !!values[index];
});
values.map(function(value) {
self.$element
.select('input[value="' + value.toString(10).replace('"', '\\"') + '"]')
.set('checked', true);
});
return self.trigger('change');
},
disable: disable,