fix a bug that would make it impossible to progamatically deselect a button in a button group

This commit is contained in:
rolux 2012-04-06 20:52:40 +02:00
parent e9f6751748
commit 8a447b8640

View file

@ -25,7 +25,7 @@ Ox.ButtonGroup = function(options, self) {
min: 1, min: 1,
selectable: false, selectable: false,
size: 'medium', size: 'medium',
style: '', style: 'default',
type: 'text', type: 'text',
value: options.max != 1 ? [] : '' value: options.max != 1 ? [] : ''
}) })
@ -88,7 +88,8 @@ Ox.ButtonGroup = function(options, self) {
}); });
self.options.value = self.optionGroup.value(); self.options.value = self.optionGroup.value();
that.triggerEvent('change', { that.triggerEvent('change', {
title: Ox.isString(self.options.value) title: self.options.value === '' ? ''
: Ox.isString(self.options.value)
? Ox.getObjectById(self.options.buttons, self.options.value).title ? Ox.getObjectById(self.options.buttons, self.options.value).title
: self.options.value.map(function(value) { : self.options.value.map(function(value) {
return Ox.getObjectById(self.options.buttons, value).title; return Ox.getObjectById(self.options.buttons, value).title;
@ -105,9 +106,14 @@ Ox.ButtonGroup = function(options, self) {
var position = Ox.getIndexById(self.options.buttons, value); var position = Ox.getIndexById(self.options.buttons, value);
if (position > -1) { if (position > -1) {
self.$buttons[position].trigger('click'); self.$buttons[position].trigger('click');
} else if (self.options.min == 0) {
self.$buttons.forEach(function($button, i) {
$button.options('value') && $button.trigger('click');
});
} }
} }
} }
return that; return that;
}; };