UNPKG

forms-reactive

Version:

Reactive Form Web Component

215 lines (214 loc) 7.25 kB
export {}; /** * @description * Provider which adds `MinLengthValidator` to the `NG_VALIDATORS` multi-provider list. */ // export const MIN_LENGTH_VALIDATOR: any = { // provide: NG_VALIDATORS, // useExisting: forwardRef(() => MinLengthValidator), // multi: true // }; /** * A directive that adds minimum length validation to controls marked with the * `minlength` attribute. The directive is provided with the `NG_VALIDATORS` multi-provider list. * * @see [Form Validation](guide/form-validation) * * @usageNotes * * ### Adding a minimum length validator * * The following example shows how to add a minimum length validator to an input attached to an * ngModel binding. * * ```html * <input name="firstName" ngModel minlength="4"> * ``` * * @ngModule ReactiveFormsModule * @ngModule FormsModule * @publicApi */ // @Directive({ // selector: '[minlength][formControlName],[minlength][formControl],[minlength][ngModel]', // providers: [MIN_LENGTH_VALIDATOR], // host: { '[attr.minlength]': 'minlength ? minlength : null' } // }) // export class MinLengthValidator implements Validator, OnChanges { // private _validator: ValidatorFn = Validators.nullValidator; // private _onChange?: () => void; // /** // * @description // * Tracks changes to the the minimum length bound to this directive. // */ // @Input() // minlength!: string | number; // This input is always defined, since the name matches selector. // /** @nodoc */ // ngOnChanges(changes: SimpleChanges): void { // if ('minlength' in changes) { // this._createValidator(); // if (this._onChange) this._onChange(); // } // } // /** // * Method that validates whether the value meets a minimum length requirement. // * Returns the validation result if enabled, otherwise null. // * @nodoc // */ // validate(control: AbstractControl): ValidationErrors | null { // return this.minlength == null ? null : this._validator(control); // } // /** // * Registers a callback function to call when the validator inputs change. // * @nodoc // */ // registerOnValidatorChange(fn: () => void): void { // this._onChange = fn; // } // private _createValidator(): void { // this._validator = Validators.minLength( // typeof this.minlength === 'number' ? this.minlength : parseInt(this.minlength, 10)); // } // } /** * @description * Provider which adds `MaxLengthValidator` to the `NG_VALIDATORS` multi-provider list. */ // export const MAX_LENGTH_VALIDATOR: any = { // provide: NG_VALIDATORS, // useExisting: forwardRef(() => MaxLengthValidator), // multi: true // }; /** * A directive that adds max length validation to controls marked with the * `maxlength` attribute. The directive is provided with the `NG_VALIDATORS` multi-provider list. * * @see [Form Validation](guide/form-validation) * * @usageNotes * * ### Adding a maximum length validator * * The following example shows how to add a maximum length validator to an input attached to an * ngModel binding. * * ```html * <input name="firstName" ngModel maxlength="25"> * ``` * * @ngModule ReactiveFormsModule * @ngModule FormsModule * @publicApi */ // @Directive({ // selector: '[maxlength][formControlName],[maxlength][formControl],[maxlength][ngModel]', // providers: [MAX_LENGTH_VALIDATOR], // host: { '[attr.maxlength]': 'maxlength ? maxlength : null' } // }) // export class MaxLengthValidator implements Validator, OnChanges { // private _validator: ValidatorFn = Validators.nullValidator; // private _onChange?: () => void; // /** // * @description // * Tracks changes to the the maximum length bound to this directive. // */ // @Input() // maxlength!: string | number; // This input is always defined, since the name matches selector. // /** @nodoc */ // ngOnChanges(changes: SimpleChanges): void { // if ('maxlength' in changes) { // this._createValidator(); // if (this._onChange) this._onChange(); // } // } // /** // * Method that validates whether the value exceeds the maximum length requirement. // * @nodoc // */ // validate(control: AbstractControl): ValidationErrors | null { // return this.maxlength != null ? this._validator(control) : null; // } // /** // * Registers a callback function to call when the validator inputs change. // * @nodoc // */ // registerOnValidatorChange(fn: () => void): void { // this._onChange = fn; // } // private _createValidator(): void { // this._validator = Validators.maxLength( // typeof this.maxlength === 'number' ? this.maxlength : parseInt(this.maxlength, 10)); // } // } /** * @description * Provider which adds `PatternValidator` to the `NG_VALIDATORS` multi-provider list. */ // export const PATTERN_VALIDATOR: any = { // provide: NG_VALIDATORS, // useExisting: forwardRef(() => PatternValidator), // multi: true // }; /** * @description * A directive that adds regex pattern validation to controls marked with the * `pattern` attribute. The regex must match the entire control value. * The directive is provided with the `NG_VALIDATORS` multi-provider list. * * @see [Form Validation](guide/form-validation) * * @usageNotes * * ### Adding a pattern validator * * The following example shows how to add a pattern validator to an input attached to an * ngModel binding. * * ```html * <input name="firstName" ngModel pattern="[a-zA-Z ]*"> * ``` * * @ngModule ReactiveFormsModule * @ngModule FormsModule * @publicApi */ // @Directive({ // selector: '[pattern][formControlName],[pattern][formControl],[pattern][ngModel]', // providers: [PATTERN_VALIDATOR], // host: { '[attr.pattern]': 'pattern ? pattern : null' } // }) // export class PatternValidator implements Validator, OnChanges { // private _validator: ValidatorFn = Validators.nullValidator; // private _onChange?: () => void; // /** // * @description // * Tracks changes to the pattern bound to this directive. // */ // @Input() // pattern!: string | RegExp; // This input is always defined, since the name matches selector. // /** @nodoc */ // ngOnChanges(changes: SimpleChanges): void { // if ('pattern' in changes) { // this._createValidator(); // if (this._onChange) this._onChange(); // } // } // /** // * Method that validates whether the value matches the the pattern requirement. // * @nodoc // */ // validate(control: AbstractControl): ValidationErrors | null { // return this._validator(control); // } // /** // * Registers a callback function to call when the validator inputs change. // * @nodoc // */ // registerOnValidatorChange(fn: () => void): void { // this._onChange = fn; // } // private _createValidator(): void { // this._validator = Validators.pattern(this.pattern); // } // } //# sourceMappingURL=validators.js.map