Travis
Travis

Reputation: 2058

How to use $valid with Angular example

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?

Upvotes: 0

Views: 866

Answers (2)

Sergio Marron
Sergio Marron

Reputation: 521

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

Upvotes: 1

BorisD
BorisD

Reputation: 189

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

Upvotes: 0

Related Questions