NgMinlength And NgMaxlength - Set length value dynamically not working #5319
Description
Hi,
I am using ng-maxlength validation directive to validate input value for max length. but I need to change the value dynamically based on some rules defined. Currently, It's setting up the value outside the maxLengthValidator function scope So it's setting value on compile time. Could you please allow to change the maxvalue length dynamically by moving var maxlength = int(attr.ngMaxlength); inside the function ? or may some other solution. ngMinlength has got the same issue
Also, It clears the invalid value from the input textbox, is it desired behaviour ? because i do not wish to clear the text box value even if it is not valid length.
// max length validator
if (attr.ngMaxlength) {
var maxlength = int(attr.ngMaxlength);
var maxLengthValidator = function(value) {
if (!ctrl.$isEmpty(value) && value.length > maxlength) {
ctrl.$setValidity('maxlength', false);
return undefined;
} else {
ctrl.$setValidity('maxlength', true);
return value;
}
};
ctrl.$parsers.push(maxLengthValidator);
ctrl.$formatters.push(maxLengthValidator);
}
}
Thanks
Kamal Patel.