summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Voborník <pvoborni@redhat.com>2012-02-22 16:23:13 +0100
committerPetr Vobornik <pvoborni@redhat.com>2012-02-29 12:59:13 +0100
commit525bf04da56829ac2b7b6e086a7a2d965727ce02 (patch)
tree9998c2d05944bd472a775614bb272c7726835c87
parent52208e8b40f98e7a7cc0c91b15803003740efa92 (diff)
downloadfreeipa.git-525bf04da56829ac2b7b6e086a7a2d965727ce02.tar.gz
freeipa.git-525bf04da56829ac2b7b6e086a7a2d965727ce02.tar.xz
freeipa.git-525bf04da56829ac2b7b6e086a7a2d965727ce02.zip
Making validators to return true result if empty
All custom validators were changed to return true result if value is empty. Raising error if value is empty is resposibility of check_required call. This fixes immediate displaying of error message in multivalued fields containing custom validators. https://fedorahosted.org/freeipa/ticket/2351
-rw-r--r--install/ui/dns.js24
-rw-r--r--install/ui/field.js41
2 files changed, 28 insertions, 37 deletions
diff --git a/install/ui/dns.js b/install/ui/dns.js
index 8125f9d3..ddd9da03 100644
--- a/install/ui/dns.js
+++ b/install/ui/dns.js
@@ -2151,16 +2151,15 @@ IPA.ip_address_validator = function(spec) {
that.validate = function(value) {
+ if (IPA.is_empty(value)) return that.true_result();
+
var address = NET.ip_address(value);
if (!address.valid || !that.is_type_match(address.type)) {
- return {
- valid: false,
- message: that.message
- };
+ return that.false_result();
}
- return { valid: true };
+ return that.true_result();
};
that.is_type_match = function(net_type) {
@@ -2203,21 +2202,10 @@ IPA.network_validator = function(spec) {
that.specials = spec.specials || [];
that.message = spec.message || IPA.messages.widget.validation.net_address;
- that.false_result = function() {
- return {
- valid: false,
- message: that.message
- };
- };
-
- that.true_result = function() {
- return {
- valid: true
- };
- };
-
that.validate = function(value) {
+ if (IPA.is_empty(value)) return that.true_result();
+
if (typeof value !== 'string') return that.false_result();
if (that.specials.indexOf(value) > -1) {
diff --git a/install/ui/field.js b/install/ui/field.js
index 01a0c0f4..4f88c16e 100644
--- a/install/ui/field.js
+++ b/install/ui/field.js
@@ -395,8 +395,23 @@ IPA.validator = function(spec) {
var that = {};
+ that.message = spec.message || IPA.messages.widget.validation.error;
+
+ that.false_result = function(message) {
+ return {
+ valid: false,
+ message: message || that.message
+ };
+ };
+
+ that.true_result = function() {
+ return {
+ valid: true
+ };
+ };
+
that.validate = function() {
- return { valid: true };
+ return that.true_result();
};
return that;
@@ -411,46 +426,34 @@ IPA.metadata_validator = function(spec) {
var message;
var metadata = context.metadata;
- if (!metadata) return { valid: true };
+ if (!metadata || IPA.is_empty(value)) return that.true_result();
if (metadata.type == 'int') {
if (!value.match(/^-?\d+$/)) {
- return {
- valid: false,
- message: IPA.messages.widget.validation.integer
- };
+ return that.false_result(IPA.messages.widget.validation.integer);
}
if (metadata.minvalue !== undefined && value < metadata.minvalue) {
message = IPA.messages.widget.validation.min_value;
message = message.replace('${value}', metadata.minvalue);
- return {
- valid: false,
- message: message
- };
+ return that.false_result(message);
}
if (metadata.maxvalue !== undefined && value > metadata.maxvalue) {
message = IPA.messages.widget.validation.max_value;
message = message.replace('${value}', metadata.maxvalue);
- return {
- valid: false,
- message: message
- };
+ return that.false_result(message);
}
}
if (metadata.pattern) {
var regex = new RegExp(metadata.pattern);
if (!value.match(regex)) {
- return {
- valid: false,
- message: metadata.pattern_errmsg
- };
+ return that.false_result(metadata.pattern_errmsg);
}
}
- return { valid: true };
+ return that.true_result();
};
return that;