From 4f648d067a463f50f9f4409b7482d0f9141563d6 Mon Sep 17 00:00:00 2001 From: gdi2290 Date: Tue, 29 Jul 2014 17:50:20 -0700 Subject: [PATCH] feat(FormController): add $submitted $setSubmitted --- src/ng/directive/form.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/ng/directive/form.js b/src/ng/directive/form.js index fd2d0b3f8e42..5f735191ff5d 100644 --- a/src/ng/directive/form.js +++ b/src/ng/directive/form.js @@ -6,9 +6,12 @@ var nullFormCtrl = { $removeControl: noop, $setValidity: noop, $setDirty: noop, + $setSubmitted: noop, $setPristine: noop }; +var SUBMITTED_CLASS = 'ng-submitted'; + /** * @ngdoc type * @name form.FormController @@ -56,6 +59,7 @@ function FormController(element, attrs, $scope, $animate) { // init state form.$name = attrs.name || attrs.ngForm; + form.$submitted = false; form.$dirty = false; form.$pristine = true; form.$valid = true; @@ -213,6 +217,20 @@ function FormController(element, attrs, $scope, $animate) { parentForm.$setDirty(); }; + + /** + * @ngdoc method + * @name form.FormController#$setSubmitted + * + * @description + * Sets the form to a submitted state. + * + */ + form.$setSubmitted = function() { + $animate.addClass(element, SUBMITTED_CLASS); + form.$submitted = true; + }; + /** * @ngdoc method * @name form.FormController#$setPristine @@ -422,6 +440,7 @@ var formDirectiveFactory = function(isNgForm) { // on a button in the form. Looks like an IE9 specific bug. var handleFormSubmission = function(event) { scope.$apply(function() { + controller.$setSubmitted(); controller.$commitViewValue(); });