Skip to content

Commit 570c576

Browse files
committed
Fixed a bug of required but disabled field
When a validation of required field but at same time is a disabled field, the validation was sometime incorrect as it tries to validate even though it's disabled. Technically a disabled field should always be valid whatsoever
1 parent 6b9f06f commit 570c576

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

angular-validation.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,14 @@
437437
isValid = testCondition(validators[j].condition, parseFloat(strValue), parseFloat(validators[j].params[0]));
438438
}
439439
}else {
440-
// run the Regex test through each iteration
441-
regex = new RegExp(validators[j].pattern, 'i');
442-
isValid = (validators[j].pattern === "required" && typeof strValue === "undefined") ? false : regex.test(strValue);
440+
// a 'disabled' element should always be valid, there is no need to validate it
441+
if(elm.prop('disabled')) {
442+
isValid = true;
443+
} else {
444+
// run the Regex test through each iteration
445+
regex = new RegExp(validators[j].pattern, 'i');
446+
isValid = (validators[j].pattern === "required" && typeof strValue === "undefined") ? false : regex.test(strValue);
447+
}
443448
}
444449
if(!isValid) {
445450
isFieldValid = false;
@@ -506,7 +511,7 @@
506511
// for the case of field that might be ng-disabled, we should skip validation
507512
// Observe the angular disabled attribute
508513
attrs.$observe("disabled",function(disabled) {
509-
if(disabled){
514+
if(disabled) {
510515
// Turn off validation when disabled
511516
ctrl.$setValidity('validation', true);
512517
} else {

0 commit comments

Comments
 (0)