2

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>
Pedro del Sol
  • 2,840
  • 9
  • 39
  • 52
SA.
  • 732
  • 7
  • 20
  • 38

2 Answers2

3

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

sylwester
  • 16,498
  • 1
  • 25
  • 33
1

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>
Nedim
  • 266
  • 2
  • 10