Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

feat(FormController): add $submitted $setSubmitted #8406

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/ng/directive/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
});

Expand Down