Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

NgMinlength And NgMaxlength - Set length value dynamically not working #5319

Closed
@kamalpatel125

Description

@kamalpatel125

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions