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.

View value not updated after $parsers run when allowInvalid: true #10126

Closed
@trevcor

Description

@trevcor

When creating a form that has the setting allowInvalid: true I noticed that I was getting false positives for ng-minlength validation. I have a directive that adds a parser that filters out invalid characters that the user may try to input. In the example below '!' is an invalid character. If the user types in 'a!' the view is updated to just 'a' but minlength=2 returns true.

This happening because this.$$parseAndValidate sets the viewValue variable before the parsers run and never updates it. This cause the original viewValue to be passed to the validators. So the minlength validator sees 'a!' instead of the current value of 'a'.

I was able to correct this behavior by updating the first line of the parsers loop to

modelValue = viewValue = ctrl.$parsers[i](modelValue);

This keeps the viewValue variable in sync but I'm unclear what side effects this might cause. Any advice is appreciated.

I'm using v1.3.0-rc.1 but I see the same behavior in 1.3.3 which is what I used for the fiddle.

Here is a example of this behavior.
http://jsfiddle.net/bq9r7b98/

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions