Allow setting multiple values for ButtonGroup
This commit is contained in:
parent
2a147446c2
commit
3d7c0d5671
1 changed files with 22 additions and 11 deletions
|
@ -31,18 +31,29 @@ Ox.ButtonGroup = function(options, self) {
|
|||
.options(options || {})
|
||||
.update({
|
||||
value: function() {
|
||||
// fixme: this doesn't work in cases where
|
||||
// multiple buttons can be selected
|
||||
var values = Ox.makeArray(self.options.value);
|
||||
|
||||
var positions = [];
|
||||
Ox.forEach(values, function(value) {
|
||||
var position = Ox.getIndexById(
|
||||
self.options.buttons, self.options.value
|
||||
self.options.buttons, value
|
||||
);
|
||||
|
||||
if (position > -1) {
|
||||
self.$buttons[position].trigger('click');
|
||||
} else if (self.options.min == 0) {
|
||||
self.$buttons.forEach(function($button, i) {
|
||||
$button.options('value') && $button.trigger('click');
|
||||
});
|
||||
positions.push(position);
|
||||
}
|
||||
});
|
||||
|
||||
if (positions.length < self.options.min) {
|
||||
return;
|
||||
}
|
||||
|
||||
Ox.forEach(self.$buttons, function(button, pos) {
|
||||
var enabled = positions.indexOf(pos) > -1;
|
||||
if (enabled !== button.value()) {
|
||||
button.trigger('click');
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
.addClass(
|
||||
|
|
Loading…
Reference in a new issue