I am trying to create a reset form using $ setPristine ().
$scope.resetDataEntryForm = function() {
$scope.dataEntryForm.$setPristine();
$scope.pr = {};
};
It works great if all input controls are in the correct state. one type of input is a URL. For example, if I have an invalid URL value when I press reset. if the reset code above contains the contents of the URL input field and mark the error false. I need this for verification.
To make a correct reset, I need to manually reset all error flags
$scope.resetDataEntryForm = function() {
$('#dataEntryForm')[0].reset();
$scope.dataEntryForm.$setPristine();
$scope.dataEntryForm.name.$error.required = true;
$scope.dataEntryForm.site.$error.required = true;
$scope.dataEntryForm.site.$error.url = false;
$scope.pr = {};
};
Can anyone suggest the correct way to reset form using angular.js?
source
share