From ff30b32188ade3d6827d4258cb54243ce3b20f01 Mon Sep 17 00:00:00 2001 From: rlx Date: Wed, 10 Feb 2016 13:15:15 +0530 Subject: [PATCH] indeterminate checkboxes... --- source/UI/js/Form/Button.js | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/source/UI/js/Form/Button.js b/source/UI/js/Form/Button.js index 337bc284..cf9c0e08 100644 --- a/source/UI/js/Form/Button.js +++ b/source/UI/js/Form/Button.js @@ -57,14 +57,14 @@ Ox.Button = function(options, self) { }, title: setTitle, value: function() { - if (self.options.values.length) { - self.options.title = Ox.getObjectById( - self.options.values, self.options.value - ).title; - setTitle(); - } + setValue(); + setTitle(); self.options.selectable && setSelected(); }, + values: function() { + setValue(); + setTitle(); + }, width: function() { that.css({width: (self.options.width - 14) + 'px'}); } @@ -105,6 +105,7 @@ Ox.Button = function(options, self) { self.options.value = self.options.value || false; } + setValue(); setTitle(); if (Ox.isArray(options.tooltip)) { @@ -171,6 +172,25 @@ Ox.Button = function(options, self) { } } + function setValue() { + if (self.options.values.length) { + self.options.values = self.options.values.map(function(value) { + return { + id: value.id || value, + title: value.title || value + }; + }); + self.value = Ox.getIndexById(self.options.values, self.options.value); + if (self.value == -1) { + self.value = 0; + self.options.value = self.options.values[0].id; + } + self.options.title = self.options.values[self.value].title; + } else if (self.options.selectable) { + self.options.value = self.options.value || false; + } + } + /*@ toggle toggle () -> toggle button