From 733a97adf87bf8f7ec6be22b37c4676cf7b5fc2b Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Sat, 7 Jul 2012 19:02:04 +0200 Subject: feat(form): add ability to reset a form to pristine state Retting a form to pristine state will cause all of the nested form and form controls to be recursively reset as well. Closes #856 --- src/ng/directive/input.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/ng/directive/input.js') diff --git a/src/ng/directive/input.js b/src/ng/directive/input.js index e17c12b3..695ca88a 100644 --- a/src/ng/directive/input.js +++ b/src/ng/directive/input.js @@ -978,6 +978,22 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$ parentForm.$setValidity(validationErrorKey, isValid, this); }; + /** + * @ngdoc function + * @name ng.directive:ngModel.NgModelController#$setPristine + * @methodOf ng.directive:ngModel.NgModelController + * + * @description + * Sets the control to its pristine state. + * + * This method can be called to remove the 'ng-dirty' class and set the control to its pristine + * state (ng-pristine class). + */ + this.$setPristine = function () { + this.$dirty = false; + this.$pristine = true; + $element.removeClass(DIRTY_CLASS).addClass(PRISTINE_CLASS); + }; /** * @ngdoc function -- cgit v1.2.3