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

Commit 3ec3566

Browse files
committed
doc(form): Minor form doc fixes and additions
Form documentation fixes: - Fix broken form example in docs - Add method documentation for $setDirty() - A few small other corrections in form docs.
1 parent 039b138 commit 3ec3566

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/ng/directive/form.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ var nullFormCtrl = {
1515
*
1616
* @property {boolean} $pristine True if user has not interacted with the form yet.
1717
* @property {boolean} $dirty True if user has already interacted with the form.
18-
* @property {boolean} $valid True if all of the containg forms and controls are valid.
18+
* @property {boolean} $valid True if all of the containing forms and controls are valid.
1919
* @property {boolean} $invalid True if at least one containing control or form is invalid.
2020
*
2121
* @property {Object} $error Is an object hash, containing references to all invalid controls or
2222
* forms, where:
2323
*
24-
* - keys are validation tokens (error names) — such as `REQUIRED`, `URL` or `EMAIL`),
24+
* - 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.
2626
*
2727
* @description
@@ -119,6 +119,19 @@ function FormController(element, attrs) {
119119
}
120120
};
121121

122+
/**
123+
* @ngdoc function
124+
* @name ng.directive:form.FormController#$setDirty
125+
* @methodOf ng.directive:form.FormController
126+
*
127+
* @description
128+
* Sets the form as dirty. This will remove the 'ng-pristine' class and add 'ng-dirty' to
129+
* the form element. This change will be propagated to all parent forms.
130+
*
131+
* Changes to an ng-model control within a form (e.g. {@link ng.directive:input input})
132+
* automatically invoke this as part of
133+
* {@link ng.directive:ngModel.NgModelController#$setViewValue $setViewValue()}.
134+
*/
122135
form.$setDirty = function() {
123136
element.removeClass(PRISTINE_CLASS).addClass(DIRTY_CLASS);
124137
form.$dirty = true;
@@ -162,7 +175,7 @@ function FormController(element, attrs) {
162175
* does not allow nesting of form elements. It is useful to nest forms, for example if the validity of a
163176
* sub-group of controls needs to be determined.
164177
*
165-
* @param {string=} ngForm|name Name of the form. If specified, the form controller will be published into
178+
* @param {string=} name|ngForm Name of the form. If specified, the form controller will be published into
166179
* related scope, under this name.
167180
*
168181
*/
@@ -235,12 +248,12 @@ function FormController(element, attrs) {
235248
</script>
236249
<form name="myForm" ng-controller="Ctrl">
237250
userType: <input name="input" ng-model="userType" required>
238-
<span class="error" ng-show="myForm.input.$error.REQUIRED">Required!</span><br>
251+
<span class="error" ng-show="myForm.input.$error.required">Required!</span><br>
239252
<tt>userType = {{userType}}</tt><br>
240253
<tt>myForm.input.$valid = {{myForm.input.$valid}}</tt><br>
241254
<tt>myForm.input.$error = {{myForm.input.$error}}</tt><br>
242255
<tt>myForm.$valid = {{myForm.$valid}}</tt><br>
243-
<tt>myForm.$error.REQUIRED = {{!!myForm.$error.REQUIRED}}</tt><br>
256+
<tt>myForm.$error.required = {{!!myForm.$error.required}}</tt><br>
244257
</form>
245258
</doc:source>
246259
<doc:scenario>

0 commit comments

Comments
 (0)