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

Commit 83f4453

Browse files
ProLoserpetebacondarwin
authored andcommitted
docs(FormController): add methods for FormController
1 parent 0cb87f9 commit 83f4453

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

src/ng/directive/form.js

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var nullFormCtrl = {
2323
*
2424
* - keys are validation tokens (error names) — such as `required`, `url` or `email`),
2525
* - values are arrays of controls or forms that are invalid with given error.
26-
*
26+
*
2727
* @description
2828
* `FormController` keeps track of all its controls and nested forms as well as state of them,
2929
* such as being valid/invalid or dirty/pristine.
@@ -62,6 +62,16 @@ function FormController(element, attrs) {
6262
addClass((isValid ? VALID_CLASS : INVALID_CLASS) + validationErrorKey);
6363
}
6464

65+
/**
66+
* @ngdoc function
67+
* @name ng.directive:form.FormController#$addControl
68+
* @methodOf ng.directive:form.FormController
69+
*
70+
* @description
71+
* Register a control with the form.
72+
*
73+
* Input elements using ngModelController do this automatically when they are linked.
74+
*/
6575
form.$addControl = function(control) {
6676
controls.push(control);
6777

@@ -70,6 +80,16 @@ function FormController(element, attrs) {
7080
}
7181
};
7282

83+
/**
84+
* @ngdoc function
85+
* @name ng.directive:form.FormController#$removeControl
86+
* @methodOf ng.directive:form.FormController
87+
*
88+
* @description
89+
* Deregister a control from the form.
90+
*
91+
* Input elements using ngModelController do this automatically when they are destroyed.
92+
*/
7393
form.$removeControl = function(control) {
7494
if (control.$name && form[control.$name] === control) {
7595
delete form[control.$name];
@@ -81,6 +101,16 @@ function FormController(element, attrs) {
81101
arrayRemove(controls, control);
82102
};
83103

104+
/**
105+
* @ngdoc function
106+
* @name ng.directive:form.FormController#$setValidity
107+
* @methodOf ng.directive:form.FormController
108+
*
109+
* @description
110+
* Sets the validity of a form control.
111+
*
112+
* This method will also propagate to parent forms.
113+
*/
84114
form.$setValidity = function(validationToken, isValid, control) {
85115
var queue = errors[validationToken];
86116

@@ -119,6 +149,17 @@ function FormController(element, attrs) {
119149
}
120150
};
121151

152+
/**
153+
* @ngdoc function
154+
* @name ng.directive:form.FormController#$setDirty
155+
* @methodOf ng.directive:form.FormController
156+
*
157+
* @description
158+
* Sets the form to a dirty state.
159+
*
160+
* This method can be called to add the 'ng-dirty' class and set the form to a dirty
161+
* state (ng-dirty class). This method will also propagate to parent forms.
162+
*/
122163
form.$setDirty = function() {
123164
element.removeClass(PRISTINE_CLASS).addClass(DIRTY_CLASS);
124165
form.$dirty = true;

0 commit comments

Comments
 (0)