i\'m trying to do a form with validations using angularjs and so far i did a good job. But when i commit my reset button all the fields reset except for the error messages i
I kept the type="reset"
in my button. What I did was the ng-click="resetForm(userForm)"
(using userFrom
to match your example) and the controller defines resetForm()
as
scope.resetForm = function(controller) {
controller.$commitViewValue();
controller.$setPristine();
};
Here is what happens:
value
attribute on the input$commitViewValue()
will force the write of whatever is on the view presently to the $modelValue
of each field (no need to iterate manually), without this the last $modelValue
would still be stored rather than reset.$setPristine()
will reset any other validation and submitted fields.In my angular-bootstrap-validator I already had the FormController
as such I didn't need to pass in the form itself.