razer90 razer90 - 1 month ago 15
AngularJS Question

prevent form from becoming invalid after press submit in angularjs

I did a validation using:

ng-show="myForm.name.$invalid && !myForm.name.$pristine"


Everything works perfectly, but when I press 'submit', I need to empty the input fields in this way:

$scope.people.name = '';
$scope.people.surname = '';


so the form becomes invalid after the submit...is there a way to prevent that? I need empty fields but a valid form...

Answer

I guess after clearing your model variables you need to set forms $pristine property

$scope.form.$setPristine();

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