diff options
author | Adam Young <ayoung@redhat.com> | 2011-07-05 10:35:50 -0400 |
---|---|---|
committer | Endi S. Dewata <edewata@redhat.com> | 2011-07-05 20:31:00 +0000 |
commit | a3a9267334ad47e78f8d3b223015b5b408a2225c (patch) | |
tree | eddfad618e3f62e05c5f1200a3b840d6c99431cc /install/ui | |
parent | 6083df1b02f545b92e8d8fd8c767f7bbd0ca4b10 (diff) | |
download | freeipa-a3a9267334ad47e78f8d3b223015b5b408a2225c.tar.gz freeipa-a3a9267334ad47e78f8d3b223015b5b408a2225c.tar.xz freeipa-a3a9267334ad47e78f8d3b223015b5b408a2225c.zip |
validate ints
validate integers whether meta comes from metadata or param_info
https://fedorahosted.org/freeipa/ticket/1415
Diffstat (limited to 'install/ui')
-rw-r--r-- | install/ui/widget.js | 73 |
1 files changed, 40 insertions, 33 deletions
diff --git a/install/ui/widget.js b/install/ui/widget.js index 2ea345d9a..cd3a5c60e 100644 --- a/install/ui/widget.js +++ b/install/ui/widget.js @@ -70,6 +70,44 @@ IPA.widget = function(spec) { that._entity_name = entity_name; }); + + function meta_validate(meta, value){ + var message; + + if (meta.type == 'int') { + if (!value.match(/^-?\d+$/)) { + that.valid = false; + that.show_error(IPA.messages.widget.validation.integer); + return; + } + + if (meta.minvalue && value < meta.minvalue) { + that.valid = false; + message = IPA.messages.widget.validation.min_value; + message = message.replace('${value}', meta.minvalue); + that.show_error(message); + return; + } + + if (meta.maxvalue && value > meta.maxvalue) { + that.valid = false; + message = IPA.messages.widget.validation.max_value; + message = message.replace('${value}', meta.maxvalue); + that.show_error(message); + return; + } + } + if (meta.pattern) { + var regex = new RegExp(meta.pattern); + if (!value.match(regex)) { + that.valid = false; + that.show_error(meta.pattern_errmsg); + return; + } + } + + } + /*returns true and clears the error message if the field value passes the validation pattern. If the field value does not pass validation, displays the error message and returns false. */ @@ -78,7 +116,6 @@ IPA.widget = function(spec) { that.hide_error(); that.valid = true; - var message; var values = that.save(); if (!values || !values.length) { @@ -97,40 +134,10 @@ IPA.widget = function(spec) { } if (that.metadata) { - if (that.metadata.type == 'int') { - if (!value.match(/^-?\d+$/)) { - that.valid = false; - that.show_error(IPA.messages.widget.validation.integer); - return; - } - - if (that.metadata.minvalue && value < that.metadata.minvalue) { - that.valid = false; - message = IPA.messages.widget.validation.min_value; - message = message.replace('${value}', that.metadata.minvalue); - that.show_error(message); - return; - } - - if (that.metadata.maxvalue && value > that.metadata.maxvalue) { - that.valid = false; - message = IPA.messages.widget.validation.max_value; - message = message.replace('${value}', that.metadata.maxvalue); - that.show_error(message); - return; - } - } + meta_validate(that.metadata,value); } - if (that.param_info) { - if (that.param_info.pattern) { - var regex = new RegExp(that.param_info.pattern); - if (!value.match(regex)) { - that.valid = false; - that.show_error(that.param_info.pattern_errmsg); - return; - } - } + meta_validate(that.param_info,value); } }; |