0

I have one input field:

<input type="text" name="title" ng-model="genreData.title" class="form-control"
        ng-class="{'error': addGenreForm.title.$invalid && !addGenreForm.title.$pristine}"
       placeholder="Genre name" ng-minlength="minlength" required autofocus>

When I succesfully submit form this input is got class="error" after this:

$scope.genreData = {};

How can I fix it?

2
  • Could you share the function which submits the form? A pseudo code could be fine. Commented Feb 2, 2017 at 13:17
  • please add the controller code. Commented Feb 2, 2017 at 13:31

2 Answers 2

1

You've got to inject the form in the ng-submit function and then call the form's controller built in function $setPristine().

e.g.

View:

<form name="myForm" ng-submit="submitForm(myForm)">
   <!--Input Fields-->
</form>

Controller:

$scope.submitForm = function(form) {
   //Do what ever I have to do
   //Then reset form
   form.$setPristine();
}
Sign up to request clarification or add additional context in comments.

Comments

0

I think setting

$scope.addGenreForm.$setPristine() and $scope.addGenreForm.$setUntouched

can work after submitting your form

Please share some plunker so I can help more if you still have any issues

2 Comments

Where to add this?
in your submmitform() function, after you have successfully submitted form

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.