Skip to content

Commit 66945e2

Browse files
committed
docs(form): improve the docs for FormController.$setValidity()
Fixes angular#15963
1 parent cd5efa0 commit 66945e2

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

src/ng/directive/form.js

+29-8
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,23 @@ function nullFormRenameControl(control, name) {
2626
* @property {boolean} $dirty True if user has already interacted with the form.
2727
* @property {boolean} $valid True if all of the containing forms and controls are valid.
2828
* @property {boolean} $invalid True if at least one containing control or form is invalid.
29-
* @property {boolean} $pending True if at least one containing control or form is pending.
3029
* @property {boolean} $submitted True if user has submitted the form even if its invalid.
3130
*
32-
* @property {Object} $error Is an object hash, containing references to controls or
33-
* forms with failing validators, where:
31+
* @property {Object} $pending An object hash, containing references to controls or forms with
32+
* pending validators, where:
33+
*
34+
* - keys are validations tokens (error names).
35+
* - values are arrays of controls or forms that have a pending validator for the given error name.
36+
*
37+
* See {@link form.FormController#$error $error} for a list of built-in validation tokens.
38+
*
39+
* @property {Object} $error An object hash, containing references to controls or forms with failing
40+
* validators, where:
3441
*
3542
* - keys are validation tokens (error names),
36-
* - values are arrays of controls or forms that have a failing validator for given error name.
43+
* - values are arrays of controls or forms that have a failing validator for the given error name.
3744
*
3845
* Built-in validation tokens:
39-
*
4046
* - `email`
4147
* - `max`
4248
* - `maxlength`
@@ -282,9 +288,24 @@ FormController.prototype = {
282288
* @name form.FormController#$setValidity
283289
*
284290
* @description
285-
* Sets the validity of a form control.
286-
*
287-
* This method will also propagate to parent forms.
291+
* Change the validity state of the form, and notify the parent form (if any).
292+
*
293+
* Application developers will rarely need to call this method directly. It is used internally, by
294+
* {@link ngModel.NgModelController#$setValidity NgModelController.$setValidity()}, to propagate a
295+
* control's validity state to the parent `FormController`.
296+
*
297+
* @param {string} validationErrorKey Name of the validator. The `validationErrorKey` will be
298+
* assigned to either `$error[validationErrorKey]` or `$pending[validationErrorKey]` (for
299+
* unfulfilled `$asyncValidators`), so that it is available for data-binding. The
300+
* `validationErrorKey` should be in camelCase and will get converted into dash-case for
301+
* class name. Example: `myError` will result in `ng-valid-my-error` and
302+
* `ng-invalid-my-error` classes and can be bound to as `{{ someForm.$error.myError }}`.
303+
* @param {boolean} isValid Whether the current state is valid (true), invalid (false), pending
304+
* (undefined), or skipped (null). Pending is used for unfulfilled `$asyncValidators`.
305+
* Skipped is used by AngularJS when validators do not run because of parse errors and when
306+
* `$asyncValidators` do not run because any of the `$validators` failed.
307+
* @param {NgModelController | FormController} controller - The controller whose validity state is
308+
* triggering the change.
288309
*/
289310
addSetValidityMethod({
290311
clazz: FormController,

src/ng/directive/ngModel.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ function setupModelWatcher(ctrl) {
940940
* (for unfulfilled `$asyncValidators`), so that it is available for data-binding.
941941
* The `validationErrorKey` should be in camelCase and will get converted into dash-case
942942
* for class name. Example: `myError` will result in `ng-valid-my-error` and `ng-invalid-my-error`
943-
* class and can be bound to as `{{someForm.someControl.$error.myError}}` .
943+
* classes and can be bound to as `{{ someForm.someControl.$error.myError }}`.
944944
* @param {boolean} isValid Whether the current state is valid (true), invalid (false), pending (undefined),
945945
* or skipped (null). Pending is used for unfulfilled `$asyncValidators`.
946946
* Skipped is used by AngularJS when validators do not run because of parse errors and

0 commit comments

Comments
 (0)