greenoldman greenoldman - 3 months ago 14
AngularJS Question

How to allow processing invalid input?

I wrote and added custom validator for input data in order to prevent form being submitted (with invalid data). And it seems as a bonus I also got no processing of invalid data -- for example

ng-change
is not triggered despite the input is changing.

So how to allow processing of the input, and tell Angular to use validators for telling is the form is valid or not only?

Here it is a simple plunker: https://plnkr.co/edit/AXNmvPUBGVNkwZazqUqW?p=preview When the validator returns always
true
,
ng-change
is triggered (see the console). Once you start real validation (in this case, non-empty input is invalid) you won't see
ng-change
fired.

Answer

It's the expected behavior, but you can use ngModelOptions directive to make it work as you're expecting.

Just add the following to your input:

ng-model-options="{allowInvalid: true}"

Look at the forked DEMO.

Comments