1

I have a form and I want to check if all the fields are valid or not.

Currently I am using four different methods. Nothing is working. Here is my plunker:

http://plnkr.co/edit/c4czI1W1fvXR4881SP1z?p=preview

Here are the methods I am using to check for validity

<button ng-click="my.$valid && validityCheck()">Update</button>
<div>myForm.$valid = {{myForm.$valid}}</div>
<span ng-show="myForm.$valid" style="color:green">Yippii!</span>
<span ng-show="myForm.$invalid" style="color:red">Not :(</span>
1
  • Where is the rest of the markup? Like the <form>? Commented Jun 3, 2016 at 18:13

1 Answer 1

2

Plunkder code has few errors.

  • Missing angular script tag
  • ng-click should refer to myForm instead of my. ng-click="myForm.$valid
  • Inject $scope to controller (or use this). function($scope){

http://plnkr.co/edit/Twz9E9LnQ08IpweLARjG

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks. Frustratingly, I can't seem to reproduce my actual problem on the same plunker. In my application, neither $valid nor $invalid are triggering. No "yippii!" or "Not :(" messages are showing, and the space for myForm.$valid is blank. Do you know if it could be in another state that is neither $valid nor $invalid?
You want to use browser debugging tool (F12) to see the JavaScript error.
No errors using the browser debugging. I can see the status of my form by inspection: <form name="myForm" class="ng-pristine ng-valid-maxlength ng-pending ng-invalid-required ng-valid-date ng-valid-firstvalidation" style="">
Parenthesis are missing. You need to use an editor. Here is the working code http://plnkr.co/edit/1iteGVImQUtkkh94TKOh.
Found out that in my code I'm running into async validation errors as described here: github.com/angular/angular.js/issues/11167 couldn't reproduce in a plunker but I accepted your answer because it solves the question here and fixes the plunker.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.