You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/content/guide/forms.ngdoc
+73-55
Original file line number
Diff line number
Diff line change
@@ -190,7 +190,7 @@ This allows us to extend the above example with these features:
190
190
191
191
192
192
193
-
# Custom triggers
193
+
# Custom model update triggers
194
194
195
195
By default, any change to the content will trigger a model update and form validation. You can
196
196
override this behavior using the {@link ng.directive:ngModelOptions ngModelOptions} directive to
@@ -267,39 +267,40 @@ This example shows how to debounce model changes. Model will be updated only 250
267
267
</file>
268
268
</example>
269
269
270
-
271
-
272
270
# Custom Validation
273
271
274
272
Angular provides basic implementation for most common HTML5 {@link ng.directive:input input}
275
-
types: ({@link input[text] text}, {@link input[number] number}, {@link input[url] url}, {@link input[email] email}, {@link input[radio] radio}, {@link input[checkbox] checkbox}), as well as some directives for validation (`required`, `pattern`, `minlength`, `maxlength`, `min`, `max`).
276
-
277
-
You can define your own validator by defining a directive which adds a validation function to the `ngModel` {@link ngModel.NgModelController controller}.
278
-
The directive can get ahold of `ngModel` by specifying `require: 'ngModel'` in the directive definition.
279
-
See below for an example.
280
-
281
-
Validation runs in two places:
282
-
283
-
* **Model to View update** -
284
-
The functions in {@link ngModel.NgModelController#$formatters `NgModelController.$formatters`} are pipelined.
285
-
Whenever the bound model changes, each of these functions has an opportunity to format the value and change validity state of the form control through {@link ngModel.NgModelController#$setValidity `NgModelController.$setValidity`}.
286
-
287
-
* **View to Model update** -
288
-
In a similar way, whenever a user interacts with a control it calls {@link ngModel.NgModelController#$setViewValue `NgModelController.$setViewValue`}.
289
-
290
-
This in turn runs all functions in the {@link ngModel.NgModelController#$parsers `NgModelController.$parsers`} array as a pipeline. Each function in `$parsers` has an opportunity to convert the value and change validity state of the form control through {@link ngModel.NgModelController#$setValidity `NgModelController.$setValidity`}.
291
-
292
-
In the following example we create two directives.
293
-
294
-
* The first one is `integer` and it validates whether the input is a valid integer.
295
-
For example `1.23` is an invalid value, since it contains a fraction.
296
-
Note that we unshift the array instead of pushing.
297
-
This is because we want it to be the first parser and consume the control string value, as we need to execute the validation function before a conversion to number occurs.
298
-
299
-
* The second directive is a `smart-float`.
300
-
It parses both `1.2` and `1,2` into a valid float number `1.2`.
301
-
Note that we can't use input type `number` here as HTML5 browsers would not allow the user to type what it would consider an invalid number such as `1,2`.
0 commit comments