3

I'm using Kelp404 for validation. After I submit the form through a HTTP post, I'm trying to reset the form.

// values set at initialization
_this.originalForm = {};
_this.formData = angular.copy(_this.originalForm);

// below code run in .then callback of http post

$scope.addCustomerForm.$setPristine();
$scope.addCustomerForm.$setUntouched();
_this.formData = angular.copy(_this.originalForm);

Now, the form is pristine and untouched with all the input variables cleared. But, the inputs are having the ng-invalid class set, which displays the error messages on the UI. I tried to set the validity also for them, but didn't help.

The code $validator.reset($scope, 'scope.formData'); is also not working

EDIT: The steps outlined in the linked question/answer do not solve the issue here

2
  • possible duplicate of Angular clear subform data and reset validation Commented Mar 23, 2015 at 16:44
  • I've got the $validator.reset() working but it shows validation errors after I nullify the model. I've fixed it by calling the $validator.reset() in a timeout block after I nullify the model. Commented Mar 28, 2015 at 13:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.