AngularJs submit form and reset $pristine state

angularjs, forms

Solution

You can call `$setPristine` on the `form`: http://plnkr.co/edit/wXaFXtuhNH6d4SP2uArm?p=preview

<button ng-click="reset(); form.$setPristine()">RESET</button>
<button ng-click="update(user); form.$setPristine()">SAVE</button>

Or you can call the method in your controller (after ensuring that the form exists):

  $scope.update = function(user) {
    $scope.master= angular.copy(user);
    if ($scope.form) $scope.form.$setPristine();
  };

  $scope.reset = function() {
    $scope.user = angular.copy($scope.master);
    if ($scope.form) $scope.form.$setPristine();
  };

Demo: http://plnkr.co/edit/Mau7uuDfPlzcn418OdWh?p=preview

Problem

Taken this form as example http://plnkr.co/edit/fHEBw6dDdG3IVgnmCLb7?p=preview How can I put the `$pristine` state of the form to true after the `SAVE DRAFT` button is pressed?

Original source