diff options
author | Petr Vobornik <pvoborni@redhat.com> | 2012-01-02 16:41:04 +0100 |
---|---|---|
committer | Endi S. Dewata <edewata@redhat.com> | 2012-01-03 21:28:45 -0600 |
commit | 911f396604f1fe3f45b5cc40e3885a975d07fa91 (patch) | |
tree | 800247c77a1e0e31ab026fadc38fcb7c5764c9d4 /install/ui | |
parent | 747c069c4579277393349c5f1f1589efb784118a (diff) | |
download | freeipa-911f396604f1fe3f45b5cc40e3885a975d07fa91.tar.gz freeipa-911f396604f1fe3f45b5cc40e3885a975d07fa91.tar.xz freeipa-911f396604f1fe3f45b5cc40e3885a975d07fa91.zip |
Added validation logic to multivalued text field
https://fedorahosted.org/freeipa/ticket/1466
Diffstat (limited to 'install/ui')
-rw-r--r-- | install/ui/field.js | 30 | ||||
-rw-r--r-- | install/ui/widget.js | 27 |
2 files changed, 55 insertions, 2 deletions
diff --git a/install/ui/field.js b/install/ui/field.js index fc6b75dda..8db0c87cb 100644 --- a/install/ui/field.js +++ b/install/ui/field.js @@ -522,7 +522,35 @@ IPA.multivalued_field = function(spec) { that.widget_value_changed = function() { that.set_dirty(that.test_dirty()); - //that.validate(); disabling validation for now + that.validate(); + }; + + that.validate = function() { + + that.hide_error(); + that.valid = true; + + var values = that.save(); + + if (that.is_empty(values)) { + return that.valid; + } + + for (var i=0; i<values.length; i++) { + + for (var j=0; j<that.validators.length; j++) { + + var validation_result = that.validators[j].validate(values[i], that); + if (!validation_result.valid) { + that.valid = false; + var row_index = that.widget.get_saved_value_row_index(i); + that.widget.show_child_error(row_index, validation_result.message); + break; + } + } + } + + return that.valid; }; return that; diff --git a/install/ui/widget.js b/install/ui/widget.js index 43910d6e6..38646c998 100644 --- a/install/ui/widget.js +++ b/install/ui/widget.js @@ -351,7 +351,7 @@ IPA.multivalued_text_widget = function(spec) { for(var i=0; i<that.rows.length; i++) { var row = that.rows[i]; row.widget.hide_undo(); - if(row.is_new) row.remove_link.show(); + row.remove_link.show(); } }; @@ -365,6 +365,31 @@ IPA.multivalued_text_widget = function(spec) { that.show_undo(); }; + that.hide_error = function() { + + that.widget_hide_error(); + + for (var i=0; i<that.rows.length; i++) { + that.rows[i].widget.hide_error(); + } + }; + + that.show_child_error = function(index, error) { + + that.rows[index].widget.show_error(error); + }; + + that.get_saved_value_row_index = function(index) { + + for (var i=0; i<that.rows.length;i++) { + + if(that.rows[i].deleted) index++; + if(i === index) return i; + } + + return -1; //error state + }; + that.save = function() { var values = []; |