0

The AngularJS documentation gives an example for custom form validation using $asyncValidators. Their example displays a message when the validation is pending or has an error. I want to display a message when the form has validated successfully.

To the best of my understanding, the the form validation API docs indicate that $valid returns a boolean, just like $pending or $error, and the $q documentation indicates that resolve() should make the form return valid.

Here's a Plunker that doesn't work. Why doesn't the success message appear when the form is valid?

Travis
  • 1,998
  • 1
  • 21
  • 36

2 Answers2

1

change

ng-show="form.name.$valid.username"

to:

ng-show="form.name.$valid"

$valid is a boolean variable not an object

here is a working demo

Sergio Marron
  • 511
  • 3
  • 9
  • What makes it work is not the code diff you posted. In the plunker you changed `ng-show="form.name.$valid.username` to `ng-show="form.name.$valid` (no username) and that is enough to make it work. – Fábio Duque Silva Feb 04 '16 at 18:26
  • $valid is a boolean variable not an object, there is no $valid.username. – Sergio Marron Feb 04 '16 at 18:36
  • Yes, exactly... which is why your previous answer (before you edited to this) was not a solution to the problem. The $valid.username -> $valid is. – Fábio Duque Silva Feb 05 '16 at 11:57
0

You can find the answer here:

Checking form inside controller:

AngularJS check if form is valid in controller

If you want form validation succes message in the template use:

Success!

formName => name attribute in your form element

Community
  • 1
  • 1
BorisD
  • 189
  • 2
  • 9