diff options
-rw-r--r-- | install/ui/field.js | 24 | ||||
-rw-r--r-- | install/ui/group.js | 2 | ||||
-rw-r--r-- | install/ui/test/widget_tests.js | 4 | ||||
-rw-r--r-- | install/ui/widget.js | 12 |
4 files changed, 24 insertions, 18 deletions
diff --git a/install/ui/field.js b/install/ui/field.js index 5f073705..162ec81b 100644 --- a/install/ui/field.js +++ b/install/ui/field.js @@ -487,6 +487,23 @@ IPA.checkbox_field = function(spec) { var that = IPA.field(spec); that.checked = spec.checked || false; + that.boolean_formatter = IPA.boolean_formatter(); + + that.load = function(record) { + + that.record = record; + + that.values = that.get_value(record, that.param); + + var value = that.boolean_formatter.parse(that.values); + if (value === '') value = that.widget.checked; //default value + + that.values = [value]; + + that.load_writable(record); + + that.reset(); + }; that.widgets_created = function() { @@ -510,13 +527,6 @@ IPA.checkboxes_field = function(spec) { var that = IPA.field(spec); - that.checkbox_load = that.load; -/* - // a checkbox will always have a value, so it's never required - that.is_required = function() { - return false; - }; -*/ return that; }; diff --git a/install/ui/group.js b/install/ui/group.js index 93b2fe0f..5ad9ba1f 100644 --- a/install/ui/group.js +++ b/install/ui/group.js @@ -140,7 +140,7 @@ IPA.group_nonposix_checkbox_widget = function (spec) { }; IPA.widget_factories['nonposix_checkbox'] = IPA.group_nonposix_checkbox_widget; -IPA.field_factories['nonposix_checkbox'] = IPA.checkbox_fields; +IPA.field_factories['nonposix_checkbox'] = IPA.checkbox_field; IPA.group_adder_dialog = function(spec) { diff --git a/install/ui/test/widget_tests.js b/install/ui/test/widget_tests.js index 951f943a..489572c2 100644 --- a/install/ui/test/widget_tests.js +++ b/install/ui/test/widget_tests.js @@ -223,7 +223,9 @@ test("Testing checkbox widget.", function() { spec = {name:'title'}; base_widget_test('test_value'); - var mock_record = { 'title': 'TRUE' }; + //Changing mock record from 'TRUE' to true. Value normalization is field's + //job. Checkbox should work with booleans values. + var mock_record = { 'title': [true] }; widget.update(mock_record.title); same(widget.save(),[true], "Checkbox is set"); diff --git a/install/ui/widget.js b/install/ui/widget.js index d46bbd8a..4ddff81f 100644 --- a/install/ui/widget.js +++ b/install/ui/widget.js @@ -632,18 +632,12 @@ IPA.checkbox_widget = function (spec) { var value; if (values && values.length) { - // use loaded value value = values[0]; - } else { - // use default value - value = that.checked; } - // convert string into boolean - if (value === 'TRUE') { - value = true; - } else if (value === 'FALSE') { - value = false; + if (typeof value !== 'boolean') { + // use default value + value = that.checked; } that.input.attr('checked', value); |