diff options
author | Petr Vobornik <pvoborni@redhat.com> | 2011-11-25 10:41:26 +0100 |
---|---|---|
committer | Endi S. Dewata <edewata@redhat.com> | 2011-12-05 16:00:39 +0000 |
commit | 863666fbe8875312c490f4747bdd30a3e0f46191 (patch) | |
tree | 452d6e1539838d37de755a8f8758b4b699327d07 /install/ui/field.js | |
parent | 4bab6b7e5d4f6454e5293c3b403fded397f93610 (diff) | |
download | freeipa-863666fbe8875312c490f4747bdd30a3e0f46191.tar.gz freeipa-863666fbe8875312c490f4747bdd30a3e0f46191.tar.xz freeipa-863666fbe8875312c490f4747bdd30a3e0f46191.zip |
Improved fields dirty status detection logic
Diffstat (limited to 'install/ui/field.js')
-rw-r--r-- | install/ui/field.js | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/install/ui/field.js b/install/ui/field.js index c9bfb700a..fb14f2eb1 100644 --- a/install/ui/field.js +++ b/install/ui/field.js @@ -261,33 +261,21 @@ IPA.field = function(spec) { */ that.test_dirty = function() { - if (that.read_only) { - return false; - } + if (that.read_only) return false; var values = that.save(); - if (!values) { // ignore null values - return false; - } + //check for empty value: null, [''], '', [] + var orig_empty = that.is_empty(that.values); + var new_empty= that.is_empty(values); + if (orig_empty && new_empty) return false; + if (orig_empty != new_empty) return true; - if (!that.values) { + //strict equality - checks object's ref equality, numbers, strings + if (values === that.values) return false; - if (values instanceof Array) { - - if ((values.length === 0) || - (values.length === 1) && - (values[0] === '')) { - return false; - } - } - - return true; - } - - if (values.length != that.values.length) { - return true; - } + //compare values in array + if (values.length !== that.values.length) return true; values.sort(); that.values.sort(); @@ -301,6 +289,22 @@ IPA.field = function(spec) { return false; }; + that.is_empty = function(value) { + + var empty = false; + + if (!value) empty = true; + + if (value instanceof Array) { + empty |= (value.length === 0) || + (value.length === 1) && (value[0] === ''); + } + + if (value === '') empty = true; + + return empty; + }; + /** * This function compares the original values and the * values entered in the UI. If the values have changed |