mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
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
This commit is contained in:
committed by
Petr Vobornik
parent
52208e8b40
commit
525bf04da5
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user