UNPKG

ngx-reactive-form-class-validator

Version:

A lightweight library for dynamically validate Angular reactive forms using class-validator library.

198 lines (189 loc) 9.76 kB
import { FormArray, AbstractControl, ValidatorFn, AbstractControlOptions, AsyncValidatorFn, FormGroup, ɵOptionalKeys as _OptionalKeys, FormControl, FormControlState } from '@angular/forms'; import * as i0 from '@angular/core'; import { ModuleWithProviders } from '@angular/core'; import * as i1 from '@angular/common'; declare class ClassValidatorFormArray extends FormArray { constructor(controls: AbstractControl[], validatorOrOpts?: ValidatorFn | ValidatorFn[] | AbstractControlOptions | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null); } declare type ClassType<T> = { new (...args: any[]): T; }; interface ClassValidatorFormGroupOptions { eagerValidation?: boolean; } declare class ClassValidatorFormGroup<TControl extends { [K in keyof TControl]: AbstractControl<any>; } = any> extends FormGroup<TControl> { private readonly formClassType; private readonly options?; private classValue; /** * Creates a new `ClassValidatorFormGroup` instance. * * @param formClassType the `classType` containing `class-validator` decorators to be used to validate form * @param controls A collection of child controls. The key for each child is the name * under which it is registered. * * @param validatorOrOpts A synchronous validator function, or an array of * such functions, or an `AbstractControlOptions` object that contains validation functions * and a validation trigger. * * @param asyncValidator A single async validator or array of async validator functions * * @param options Options object of type `ClassValidatorFormGroupOptions` allowing * to define eagerValidation that validate controls immediately upon creation. Default is false (validators are executed starting from ngAfterViewInit hook) * See https://github.com/abarghoud/ngx-reactive-form-class-validator/issues/47 * */ constructor(formClassType: ClassType<any>, controls: TControl, validatorOrOpts?: ValidatorFn | ValidatorFn[] | AbstractControlOptions | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null, options?: ClassValidatorFormGroupOptions); /** * Add a control to this group. * * This method also updates the value and validity of the control. * * @param name The control name to add to the collection * @param control Provides the control for the given name * @param options Specifies whether this FormGroup instance should emit events after a new * control is added. * * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and * `valueChanges` observables emit events with the latest status and value when the control is * added. When false, no events are emitted. * */ addControl<K extends string & keyof TControl>(name: K, control: Required<TControl>[K], options?: { emitEvent?: boolean; }): void; /** * Remove a control from this group. * * @param name The control name to remove from the collection * @param options Specifies whether this FormGroup instance should emit events after a * control is removed. * * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and * `valueChanges` observables emit events with the latest status and value when the control is * removed. When false, no events are emitted. */ removeControl<S extends string>(name: _OptionalKeys<TControl> & S, options?: { emitEvent?: boolean; }): void; private setClassValidatorControlsContainerGroupClassValue; private assignFormValueToClassValue; } declare class ClassValidatorFormControl<T = any> extends FormControl<T | any> { private formGroupClassValue; private name; /** * Creates a new `ClassValidatorFormControl` instance. * * @param formState Initializes the control with an initial value, * or an object that defines the initial value and disabled state. * * @param validatorOrOpts A synchronous validator function, or an array of * such functions, or an `AbstractControlOptions` object that contains validation functions * and a validation trigger. * * @param asyncValidator A single async validator or array of async validator functions * */ constructor(formState?: any, validatorOrOpts?: ValidatorFn | ValidatorFn[] | AbstractControlOptions | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null); /** * @internal */ setNameAndFormGroupClassValue(name: string, value: any, eagerValidation?: boolean): void; /** * Sets the synchronous validators that are active on this control as well as resetting the dynamic `class-validator`. Calling * this overwrites any existing sync validators. * * When you add or remove a validator at run time, you must call * `updateValueAndValidity()` for the new validation to take effect. * */ setValidatorsWithDynamicValidation(newValidator: ValidatorFn | ValidatorFn[] | AbstractControlOptions | undefined): void; private composeValidators; private readonly dynamicValidator; } declare class ClassValidatorFormBuilderService { /** * @description * Construct a new `FormGroup` instance. * * @param formClassType the `classType` containing `class-validator` decorators to be used to validate form * @param controlsConfig A collection of child controls. The key for each child is the name * under which it is registered. * * @param options Configuration options object for the `FormGroup`. The object can * have two shapes: * * 1) `AbstractControlOptions` object (preferred), which consists of: * * `validators`: A synchronous validator function, or an array of validator functions * * `asyncValidators`: A single async validator or array of async validator functions * * `updateOn`: The event upon which the control should be updated (options: 'change' | 'blur' | * submit') * * 2) Legacy configuration object, which consists of: * * `validator`: A synchronous validator function, or an array of validator functions * * `asyncValidator`: A single async validator or array of async validator functions * * @param classValidatorGroupOptions Options object of type `ClassValidatorFormGroupOptions` allowing * to define eagerValidation that validate controls immediately upon creation. Default is false (validators are executed starting from ngAfterViewInit hook) * See https://github.com/abarghoud/ngx-reactive-form-class-validator/issues/47 * */ group(formClassType: ClassType<any>, controlsConfig: { [p: string]: any; }, options?: AbstractControlOptions | { [p: string]: any; } | null, classValidatorGroupOptions?: ClassValidatorFormGroupOptions): ClassValidatorFormGroup; /** * Constructs a new `FormArray` from the given array of configurations, * validators and options. * * @param controlsConfig An array of child controls or control configs. Each * child control is given an index when it is registered. * * @param validatorOrOpts A synchronous validator function, or an array of * such functions, or an `AbstractControlOptions` object that contains * validation functions and a validation trigger. * * @param asyncValidator A single async validator or array of async validator * functions. */ array<T>(controlsConfig: Array<T>, validatorOrOpts?: ValidatorFn | ValidatorFn[] | AbstractControlOptions | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null): FormArray; /** * @description * Construct a new `FormControl` with the given state, validators and options. * * @param formState Initializes the control with an initial state value, or * with an object that contains both a value and a disabled status. * * @param validatorOrOpts A synchronous validator function, or an array of * such functions, or an `AbstractControlOptions` object that contains * validation functions and a validation trigger. * * @param asyncValidator A single async validator or array of async validator * functions. * * @usageNotes * * ### Initialize a control as disabled * * The following example returns a control with an initial value in a disabled state. * * <code-example path="forms/ts/formBuilder/form_builder_example.ts" region="disabled-control"> * </code-example> */ control<T>(formState: T | FormControlState<T>, validatorOrOpts?: ValidatorFn | ValidatorFn[] | AbstractControlOptions | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null): ClassValidatorFormControl; private reduceControls; private createControl; static ɵfac: i0.ɵɵFactoryDeclaration<ClassValidatorFormBuilderService, never>; static ɵprov: i0.ɵɵInjectableDeclaration<ClassValidatorFormBuilderService>; } declare class ClassValidatorFormBuilderModule { static forRoot(): ModuleWithProviders<ClassValidatorFormBuilderModule>; static ɵfac: i0.ɵɵFactoryDeclaration<ClassValidatorFormBuilderModule, never>; static ɵmod: i0.ɵɵNgModuleDeclaration<ClassValidatorFormBuilderModule, never, [typeof i1.CommonModule], never>; static ɵinj: i0.ɵɵInjectorDeclaration<ClassValidatorFormBuilderModule>; } export { ClassValidatorFormArray, ClassValidatorFormBuilderModule, ClassValidatorFormBuilderService, ClassValidatorFormControl, ClassValidatorFormGroup }; export type { ClassType }; //# sourceMappingURL=ngx-reactive-form-class-validator.d.ts.map