summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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;