docs(API): 翻译完了 Validators

This commit is contained in:
Zhicheng Wang 2018-09-02 19:23:29 +08:00
parent de47500c53
commit 8cea4a3646
2 changed files with 76 additions and 2 deletions

View File

@ -34,7 +34,7 @@
[x] | common/UpperCasePipe | 0.65
[x] | common/NgStyle | 0.60
[x] | router/RouterOutlet | 0.59
[ ] | forms/Validators | 0.59
[x] | forms/Validators | 0.59
[ ] | common/http/HttpHeaders | 0.56
[x] | core/Pipe | 0.52
[ ] | common/NgSwitch | 0.52

View File

@ -21,15 +21,21 @@ function isEmptyInputValue(value: any): boolean {
* @description
* An `InjectionToken` for registering additional synchronous validators used with `AbstractControl`s.
*
* `InjectionToken` `AbstractControl` 使
*
* @see `NG_ASYNC_VALIDATORS`
*
* @usageNotes
*
* ### Providing a custom validator
*
* ###
*
* The following example registers a custom validator directive. Adding the validator to the
* existing collection of validators requires the `multi: true` option.
*
* 使 `multi: true`
*
* ```typescript
* @Directive({
* selector: '[customValidator]',
@ -49,6 +55,8 @@ export const NG_VALIDATORS = new InjectionToken<Array<Validator|Function>>('NgVa
* @description
* An `InjectionToken` for registering additional asynchronous validators used with `AbstractControl`s.
*
* `InjectionToken` `AbstractControl` 使
*
* @see `NG_VALIDATORS`
*
*/
@ -62,11 +70,16 @@ const EMAIL_REGEXP =
* @description
* Provides a set of built-in validators that can be used by form controls.
*
*
*
* A validator is a function that processes a `FormControl` or collection of
* controls and returns an error map or null. A null map means that validation has passed.
*
*
* `FormControl` map nullnull
*
* @see [Form Validation](/guide/form-validation)
*
* [](/guide/form-validation)
*/
export class Validators {
/**
@ -74,10 +87,15 @@ export class Validators {
* Validator that requires the control's value to be greater than or equal to the provided number.
* The validator exists only as a function and not as a directive.
*
*
*
*
* @usageNotes
*
* ### Validate against a minimum of 3
*
* ### 3
*
* ```typescript
* const control = new FormControl(2, Validators.min(3));
*
@ -87,6 +105,7 @@ export class Validators {
* @returns A validator function that returns an error map with the
* `min` property if the validation check fails, otherwise `null`.
*
* `min` map `null`
*/
static min(min: number): ValidatorFn {
return (control: AbstractControl): ValidationErrors | null => {
@ -105,10 +124,15 @@ export class Validators {
* Validator that requires the control's value to be less than or equal to the provided number.
* The validator exists only as a function and not as a directive.
*
*
*
*
* @usageNotes
*
* ### Validate against a maximum of 15
*
* ### 15
*
* ```typescript
* const control = new FormControl(16, Validators.max(15));
*
@ -118,6 +142,8 @@ export class Validators {
* @returns A validator function that returns an error map with the
* `max` property if the validation check fails, otherwise `null`.
*
* `max` map `null`
*
*/
static max(max: number): ValidatorFn {
return (control: AbstractControl): ValidationErrors | null => {
@ -135,10 +161,14 @@ export class Validators {
* @description
* Validator that requires the control have a non-empty value.
*
*
*
* @usageNotes
*
* ### Validate that the field is non-empty
*
* ###
*
* ```typescript
* const control = new FormControl('', Validators.required);
*
@ -148,6 +178,7 @@ export class Validators {
* @returns An error map with the `required` property
* if the validation check fails, otherwise `null`.
*
* `required` map `null`
*/
static required(control: AbstractControl): ValidationErrors|null {
return isEmptyInputValue(control.value) ? {'required': true} : null;
@ -158,10 +189,14 @@ export class Validators {
* Validator that requires the control's value be true. This validator is commonly
* used for required checkboxes.
*
*
*
* @usageNotes
*
* ### Validate that the field value is true
*
* ###
*
* ```typescript
* const control = new FormControl('', Validators.requiredTrue);
*
@ -170,6 +205,8 @@ export class Validators {
*
* @returns An error map that contains the `required` property
* set to `true` if the validation check fails, otherwise `null`.
*
* `required` `true` map `null`
*/
static requiredTrue(control: AbstractControl): ValidationErrors|null {
return control.value === true ? null : {'required': true};
@ -179,10 +216,14 @@ export class Validators {
* @description
* Validator that requires the control's value pass an email validation test.
*
* email
*
* @usageNotes
*
* ### Validate that the field matches a valid email pattern
*
* ### email
*
* ```typescript
* const control = new FormControl('bad@', Validators.email);
*
@ -192,6 +233,8 @@ export class Validators {
* @returns An error map with the `email` property
* if the validation check fails, otherwise `null`.
*
* `email` map `null`
*
*/
static email(control: AbstractControl): ValidationErrors|null {
if (isEmptyInputValue(control.value)) {
@ -206,10 +249,14 @@ export class Validators {
* to the provided minimum length. This validator is also provided by default if you use the
* the HTML5 `minlength` attribute.
*
* 使 HTML5 `minlength`
*
* @usageNotes
*
* ### Validate that the field has a minimum of 3 characters
*
* ### 3
*
* ```typescript
* const control = new FormControl('ng', Validators.minLength(3));
*
@ -222,6 +269,9 @@ export class Validators {
*
* @returns A validator function that returns an error map with the
* `minlength` if the validation check fails, otherwise `null`.
*
* `minlength` map `null`
*
*/
static minLength(minLength: number): ValidatorFn {
return (control: AbstractControl): ValidationErrors | null => {
@ -241,10 +291,14 @@ export class Validators {
* to the provided maximum length. This validator is also provided by default if you use the
* the HTML5 `maxlength` attribute.
*
* 使 HTML5 `maxlength`
*
* @usageNotes
*
* ### Validate that the field has maximum of 5 characters
*
* ### 5
*
* ```typescript
* const control = new FormControl('Angular', Validators.maxLength(5));
*
@ -257,6 +311,8 @@ export class Validators {
*
* @returns A validator function that returns an error map with the
* `maxlength` property if the validation check fails, otherwise `null`.
*
* `maxlength` map `null`
*/
static maxLength(maxLength: number): ValidatorFn {
return (control: AbstractControl): ValidationErrors | null => {
@ -273,10 +329,14 @@ export class Validators {
* provided
* by default if you use the HTML5 `pattern` attribute.
*
* 使 HTML5 `pattern`
*
* @usageNotes
*
* ### Validate that the field only contains letters or spaces
*
* ###
*
* ```typescript
* const control = new FormControl('1', Validators.pattern('[a-zA-Z ]*'));
*
@ -289,6 +349,9 @@ export class Validators {
*
* @returns A validator function that returns an error map with the
* `pattern` property if the validation check fails, otherwise `null`.
*
* `pattern` map `null`
*
*/
static pattern(pattern: string|RegExp): ValidatorFn {
if (!pattern) return Validators.nullValidator;
@ -321,6 +384,8 @@ export class Validators {
/**
* @description
* Validator that performs no operation.
*
*
*/
static nullValidator(c: AbstractControl): ValidationErrors|null { return null; }
@ -329,8 +394,13 @@ export class Validators {
* Compose multiple validators into a single function that returns the union
* of the individual error maps for the provided control.
*
*
*
* @returns A validator function that returns an error map with the
* merged error maps of the validators if the validation check fails, otherwise `null`.
*
* `null`
*
*/
static compose(validators: null): null;
static compose(validators: (ValidatorFn|null|undefined)[]): ValidatorFn|null;
@ -349,8 +419,12 @@ export class Validators {
* Compose multiple async validators into a single function that returns the union
* of the individual error objects for the provided control.
*
*
*
* @returns A validator function that returns an error map with the
* merged error objects of the async validators if the validation check fails, otherwise `null`.
*
* `null`
*/
static composeAsync(validators: (AsyncValidatorFn|null)[]): AsyncValidatorFn|null {
if (!validators) return null;