Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove ng-submitted after successful submission

I have a form that submits via an api and can be reused immediately after the post request has finished.

For validation styling requirements I need to remove the css class ng-submitted from the <form> I can't seem to find an angular method for clearing it, or resetting the form.

I have tried:

myForm.$submitted = false;

but this does not remove the ng-submitted class

Does such a method exist in angular 1.3?

like image 557
James Avatar asked Mar 05 '15 11:03

James


People also ask

How to reset form after submit Angular?

import { FormsModule } from '@angular/forms'; In Reactive forms, we need to import FormGroup from '@angular/forms' . After importing the above-mentioned modules in the respective approach, angular forms module provides an inbuilt method called reset(). We can use the method and we can reset the form.

How to reset the form in Angular?

In a model-driven form to reset the form we just need to call the function reset() on our myform model. The form now resets, all the input fields go back to their initial state and any valid , touched or dirty properties are also reset to their starting values.

What is pristine in angular?

ng-pristine The field has not been modified yet. ng-dirty The field has been modified. ng-valid The field content is valid. ng-invalid The field content is not valid.

What is the use of NG submit?

The ng-submit directive specifies a function to run when the form is submitted. If the form does not have an action ng-submit will prevent the form from being submitted.


1 Answers

hi I think you need to do this:

myForm.$setPristine();
myForm.$setUntouched();

this will clear the submit state and all fields will be untouched, this does not clear the field values though so if you want that you need to do this separately

like image 198
kruczy Avatar answered Oct 09 '22 14:10

kruczy