Note that there are some explanatory texts on larger screens.

plurals
  1. POClearing all inputs and restoring .ng-pristine on click
    primarykey
    data
    text
    <p>It's still the first day of me using AngularJS after inheriting the project from a fellow developer. I was wondering, I have a login/registration form on my interface that is hidden once the items/form is submitted. Now once the user has submitted is there a correct or proper way to clear the form of it's entries and restore the .ng-pristine class on the items. The reason for this is should the user choose to log out and then login again (or another user wishes to register) the form is populated and has the validation css applied to it already. I don't want this, I would want everything to be empty and no CSS applied.</p> <p>I can do this in JavaScript (obviously) however with AngularJS being a different approach I was wondering if I should approach this issue another way rather than loop through the form items and append a class to each item whilst clearing it's value.</p> <p>This an example of one of my forms </p> <pre><code>&lt;form name="signupForm" novalidate ng-submit="register(user)"&gt; &lt;div&gt;&lt;label for="email"&gt;email:&lt;/label&gt;&lt;input type="email" id="email" name="email" required ng-model="user.email" ng-minlength=4&gt;&lt;/div&gt; &lt;div&gt;&lt;label for="userName"&gt;Username:&lt;/label&gt;&lt;input type="text" name="userName" id="userName" ng-model="user.userName" required ng-pattern="/^[A-Za-z0-9 \-_.]*$/" ng-minlength=4&gt;&lt;/div&gt; &lt;div&gt;&lt;label for="firstName"&gt;Vorname:&lt;/label&gt;&lt;input type="text" name="firstName" id="firstName" ng-model="user.firstName" required ng-pattern="/^[A-Za-z \-_.]*$/" ng-minlength=3&gt;&lt;/div&gt; &lt;div&gt;&lt;label for="lastName"&gt;Nachname:&lt;/label&gt;&lt;input type="text" name="lastName" id="lastName" ng-model="user.lastName" required ng-pattern="/^[A-Za-z \-_.]*$/" ng-minlength=4&gt;&lt;/div&gt; &lt;div&gt;&lt;label for="password1"&gt;Passwort:&lt;/label&gt;&lt;input type="password" name="password1" id="password1" ng-model="user.password1" required ng-minlength=4&gt;&lt;/div&gt; &lt;div&gt;&lt;label for="password2"&gt;Passwort wiederholen:&lt;/label&gt;&lt;input type="password" name="password2" id="password2" ng-model="user.password2" valid-password2 ng-minlength=4 pw-check="password1"&gt;&lt;/div&gt; ... and so on </code></pre> <p>Many thanks</p>
    singulars
    1. This table or related slice is empty.
    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.
    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