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,
+2 -7
View File
@@ -3,13 +3,8 @@
<div class="checkbox-group">
{{each options}}
<label class="tap-highlight">
<span class="label">{{{this.label}}}</span>
<input
type="checkbox"
value="{{this.value}}"
name="clay-{{clayId}}"
{{each key: attributes}}{{key}}="{{this}}"{{/each}}
/>
<span class="label">{{{this}}}</span>
<input type="checkbox" value="1" name="clay-{{clayId}}" />
<i></i>
</label>
{{/each}}