From 3d7c0d567153866c253d461dee1a5e3f8c39513d Mon Sep 17 00:00:00 2001 From: qsniyg Date: Mon, 4 Sep 2023 22:36:32 +0000 Subject: [PATCH] Allow setting multiple values for ButtonGroup --- source/UI/js/Form/ButtonGroup.js | 33 +++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/source/UI/js/Form/ButtonGroup.js b/source/UI/js/Form/ButtonGroup.js index c1c5ff5e..b4ff9ef1 100644 --- a/source/UI/js/Form/ButtonGroup.js +++ b/source/UI/js/Form/ButtonGroup.js @@ -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 position = Ox.getIndexById( - self.options.buttons, self.options.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'); - }); + var values = Ox.makeArray(self.options.value); + + var positions = []; + Ox.forEach(values, function(value) { + var position = Ox.getIndexById( + self.options.buttons, value + ); + + if (position > -1) { + 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( -- 2.39.5