diff options
author | Petr Vobornik <pvoborni@redhat.com> | 2012-03-09 15:52:05 +0100 |
---|---|---|
committer | Petr Vobornik <pvoborni@redhat.com> | 2012-03-15 16:09:52 +0100 |
commit | 049cc6cd8ad7a6fcac1b4578a21d81a62c927937 (patch) | |
tree | 79aa4828ddd85904642ef3b74c80be9f88f42a8d /install | |
parent | 16918715dd4b964d5d861a3075b356918034e908 (diff) | |
download | freeipa.git-049cc6cd8ad7a6fcac1b4578a21d81a62c927937.tar.gz freeipa.git-049cc6cd8ad7a6fcac1b4578a21d81a62c927937.tar.xz freeipa.git-049cc6cd8ad7a6fcac1b4578a21d81a62c927937.zip |
Fixed evaluating checkbox dirty status
Problem:
When value in checkbox is modified twice in a row (so it is at its original value) an 'undo' button is still visible even when it shouldn't be.
Cause:
IPA server sends boolean values as 'TRUE' or 'FALSE' (strings). Checkbox_widget converts them to JavaScript? boolean (true, false). Save method in checkbox_widget is returning array with a boolean. So test_dirty method always evaluates to dirty because 'FALSE' != false.
This patch is fixing the problem.
https://fedorahosted.org/freeipa/ticket/2494
Diffstat (limited to 'install')
-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); |