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');         }     } }); 

fiddle demo

if setting blank value $scope.note['title'] = null; shows error after clearing.

fiddle demo

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. }; 

demo fiddle


Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -