javascript - Angular form reset after validation -
i using angular js validation on form working fine after form valid sending ajax request , resting jquery code, form still shows valid. here following js snippet:
var myapp = angular.module('myapp', []); myapp.controller('mycontroller', function ($scope) { $scope.clearform = function (formid) { $(formid)[0].reset(); console.log($scope.note['title']) //$scope.note['title'] = null; }; $scope.submitform = function () { if ($scope.noteform.$valid) { alert("valid"); //ajax request $scope.clearform('#noteform'); } } }); if setting blank value $scope.note['title'] = null; shows error after clearing.
how can resolve this? want after resting should goes initial state.
rather clearing form in jquery, i'd prefer use $setpristine() method on form make form pristine in angular way. need clear form fields doing $scope.note = {}.
code
$scope.clearform = function (formid) { $scope.noteform.$setpristine(); //you should use setpristine make pristine $scope.note = {}; //this clear form values. };
Comments
Post a Comment