Note that there are some explanatory texts on larger screens.

plurals
  1. POAngularJs empty form and remove invalid state from inputs
    primarykey
    data
    text
    <p>I'm using a form to add elements to list that is displayed on the side of the form. Markup is: </p> <pre><code> &lt;form name="thingForm"&gt; &lt;input required type="text" ng-model="thing.name"/&gt; &lt;input required type="text" ng-model="thing.value"/&gt; &lt;input type="submit" ng-click="addThing(thing)"/&gt; &lt;/form&gt; &lt;ul&gt; &lt;li ng-repeat="thing in things"&gt;{{thing.name}} with value of {{thing.value}}&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>And in a controller I have: </p> <pre><code>$scope.things = []; $scope.addThing = function(thing) { $scope.things.push(thing); $scope.thing = {}; }; </code></pre> <p>Working jsfiddle: <a href="http://jsfiddle.net/cXU2H/1/" rel="nofollow noreferrer">http://jsfiddle.net/cXU2H/1/</a></p> <p>Now as you can see, I can empty the form by emptying the model, however since the inputs have the required tag the browser still displays an error message (at least Chrome does). </p> <p>I looked at the similar questions and:</p> <ul> <li>I've also looked at this answer: <a href="https://stackoverflow.com/a/16296941/545925">https://stackoverflow.com/a/16296941/545925</a> however the jsfiddle behaves exactly the same as in my example: after the input is cleared it still has an <code>ng-invalid-required</code> class remaining (and it also triggers a HTML5 error message)</li> <li><del>since I'm not on the 1.1.x branch <code>$setPristine()</code> is not available for me</del> <code>$setPristine()</code> behaves the same way</li> </ul> <p>I can of course write a function that iterates through the elements of a form and removes every <code>ng-invalid-required</code> and <code>ng-invalid</code> class, but that is not the way I would like to solve this. That is what I would do with jQuery.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload