Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJs .$setPristine to reset form

Tags:

angularjs

I been struggling to reset form once form is submitted. Someone posted this Here which I want to make it work but no success. Here is my My Code Example.

$scope.form.$setPristine(); is not setting Pristine: {{user_form.$pristine}} to true. See example above.

like image 237
Pirzada Avatar asked May 26 '13 12:05

Pirzada


People also ask

How to use setPristine in AngularJS?

$setPristine();Sets the form to its pristine state. This method sets the form's $pristine state to true, the $dirty state to false, removes the ng-dirty class and adds the ng-pristine class. Additionally, it sets the $submitted state to false.

What is $dirty in Angularjs?

$dirty means the user has changed the input value, $invalid means the address itself is invalid. Therefore the error is only shown if the user has actively changed the input value to either an empty or invalid value.

What is pristine angular form?

pristine: This property returns true if the element's contents have not been changed. dirty: This property returns true if the element's contents have been changed.


1 Answers

$setPristine() was introduced in the 1.1.x branch of angularjs. You need to use that version rather than 1.0.7 in order for it to work.

See http://plnkr.co/edit/815Bml?p=preview

like image 66
Lucas Holt Avatar answered Sep 29 '22 12:09

Lucas Holt