diff options
author | Adam Young <ayoung@redhat.com> | 2010-10-27 13:41:48 -0400 |
---|---|---|
committer | Endi Sukma Dewata <edewata@redhat.com> | 2010-10-28 03:06:28 -0400 |
commit | 97bcbdec2f9b2c2b88208ad969fb378a29fe9378 (patch) | |
tree | ba361531a45de7d0d37523748e483eb0d311bd68 | |
parent | 43212caf5d22a6965be0cdced521288dd6df097c (diff) | |
download | freeipa-97bcbdec2f9b2c2b88208ad969fb378a29fe9378.tar.gz freeipa-97bcbdec2f9b2c2b88208ad969fb378a29fe9378.tar.xz freeipa-97bcbdec2f9b2c2b88208ad969fb378a29fe9378.zip |
Field Errors Uses the pattern field of the metat data to see if the input for a given field is valid. If not, displays a red box with the contents of pattern_msg
To test this, I artificially modified the meta data for the Group description field
-rw-r--r-- | install/static/details.js | 29 | ||||
-rw-r--r-- | install/static/test/data/json_metadata.json | 6 |
2 files changed, 26 insertions, 9 deletions
diff --git a/install/static/details.js b/install/static/details.js index 312ad950f..d0688f55d 100644 --- a/install/static/details.js +++ b/install/static/details.js @@ -123,6 +123,7 @@ function ipa_stanza(spec){ var value = $.trim(input.val()); if (!value) value = ''; + values.push(value); }); @@ -480,20 +481,34 @@ function _ipa_create_text_input(attr, value, param_info) return index; } + function validate_input(text, param_info,error_link){ + if(param_info && param_info.pattern){ + var regex = new RegExp( param_info.pattern ); + if (!text.match(regex)) { + error_link.style.display ="block"; + if ( param_info.pattern_errmsg){ + error_link.innerHTML = param_info.pattern_errmsg; + } + }else{ + error_link.style.display ="none"; + } + } + } + var input = $("<Span />"); input.append($("<input/>",{ type:"text", name:attr, value:value.toString(), - keypress: function(){ - var validation_info=param_info; + keyup: function(){ var undo_link=this.nextElementSibling; undo_link.style.display ="inline"; - if(false){ - var error_link = undo_link.nextElementSibling; - error_link.style.display ="block"; - } + var error_link = undo_link.nextElementSibling; + + var text = $(this).val(); + validate_input(text, param_info,error_link); } + })); input.append($("<a/>",{ html:"undo", @@ -515,6 +530,8 @@ function _ipa_create_text_input(attr, value, param_info) this.previousElementSibling.value = previous_value; this.style.display = "none"; + var error_link = this.nextElementSibling; + validate_input(previous_value, param_info,error_link); } })); input.append($("<span/>",{ diff --git a/install/static/test/data/json_metadata.json b/install/static/test/data/json_metadata.json index 8571ddf68..a005d1d5f 100644 --- a/install/static/test/data/json_metadata.json +++ b/install/static/test/data/json_metadata.json @@ -1098,8 +1098,8 @@ "minlength": null, "multivalue": false, "name": "description", - "pattern": null, - "pattern_errmsg": null, + "pattern": "^[a-zA-Z-2-9_. ]{0,30}[a-zA-Z0-9_.$-]?$", + "pattern_errmsg": "may only include letters, numbers, _, -, . and $", "primary_key": false, "query": false, "required": true, @@ -4474,4 +4474,4 @@ } } } -}
\ No newline at end of file +} |