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>
4
  • what´s in the validateCtrl? Commented Sep 17, 2014 at 10:37
  • @s-hoff: I have removed validatectrl from code Commented Sep 17, 2014 at 11:09
  • should work just fine then (plunk) Commented Sep 17, 2014 at 15:49
  • Same here @kawade I face the same problem. Validations not working and all the validations are visible on the page(chrome) Commented Jun 12, 2015 at 5:53

2 Answers 2

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

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

2 Comments

I have removed ng-controller="validateCtrl", but still not working
@kawade in that case if you using chrome pres ctrl-shift+j refresh your page and check if there any error occurred
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>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.