SA.
SA.

Reputation: 752

angular validation not working

I am using angular validation on an html page, where I have defined a form along with validation on the form. However, when I run the page, all the validations I have used on the page is visible. Is there a way I can hide all the validations?

 <form ng-controller="validateCtrl"
       name="loginForm" novalidate>

    <p>UserName:<br>
        <input type="text" name="uName" ng-model="uName" required>
  <span style="color:red" ng-show="loginForm.uName.$dirty && loginForm.uName.$invalid && loginForm.uName.$error.required">
      Username is required
  </span>
    </p>

    <p>Password:<br>
        <input type="text" name="pwd" ng-model="pwd" required>
  <span style="color:red" ng-show="loginForm.pwd.$dirty && loginForm.pwd.$invalid">
    <span ng-show="loginForm.pwd.$error.required">Password is required.</span>
  </span>
    </p>

    <p>
        <input type="submit" ng-click="popupuser()"
               ng-disabled="loginForm.$invalid ">
    </p>

</form>
<script src="https://code.angularjs.org/1.2.3/angular.min.js"></script>

Upvotes: 2

Views: 17748

Answers (2)

sylwester
sylwester

Reputation: 16498

Your code for form is fine please see here http://jsbin.com/figuve/1/edit

Make sure that your validateCtrl exist otherwise validation will not work plase see here http://jsbin.com/figuve/2/edit

or

remove ng-controller="validateCtrl" from your form if you don't need it. please see here http://jsbin.com/figuve/3/edit

Upvotes: 3

Nedim
Nedim

Reputation: 266

You can try use variable to check is form submited, like that

 <span ng-show="(loginForm.uName.$dirty || isSubmitted) && loginForm.uName.$error.required">Username is required</span>

Upvotes: 1

Related Questions