razer90 razer90 - 1 year ago 60
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 Source

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



Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download