Allow setting multiple values for ButtonGroup

This commit is contained in:
qsniyg 2023-09-04 22:36:32 +00:00 committed by j
parent 2c4e0b8f7b
commit d71ad7cad6

View file

@ -31,18 +31,29 @@ Ox.ButtonGroup = function(options, self) {
.options(options || {}) .options(options || {})
.update({ .update({
value: function() { value: function() {
// fixme: this doesn't work in cases where var values = Ox.makeArray(self.options.value);
// multiple buttons can be selected
var position = Ox.getIndexById( var positions = [];
self.options.buttons, self.options.value Ox.forEach(values, function(value) {
); var position = Ox.getIndexById(
if (position > -1) { self.options.buttons, value
self.$buttons[position].trigger('click'); );
} else if (self.options.min == 0) {
self.$buttons.forEach(function($button, i) { if (position > -1) {
$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( .addClass(