UNPKG

@yyasinaslan/easyform

Version:
65 lines (64 loc) 2.74 kB
import { FormSchema } from "./interfaces/form-schema"; import { Validation } from "./interfaces/validation"; import { Signal } from "@angular/core"; import { Observable } from "rxjs"; import { FormControl, FormGroup } from "@angular/forms"; import { BasicControlTypes } from "./interfaces/basic-control-types"; import { EasyFormGenerator } from "./easy-form-generator"; import { EasyFormControlComponent, LazyLoadingComponent } from "./tokens/easy-form-config"; import { EasyFormField } from "./easy-form-field"; export interface EasyFormOptions { showErrors?: 'submitted' | 'touched' | 'dirty' | 'always' | 'never'; validations?: Record<string, Validation>; disabled?: boolean | Signal<boolean> | Observable<boolean>; components?: Record<string, EasyFormControlComponent | LazyLoadingComponent>; } export type InferValueType<Schema extends FormSchema> = { [key in keyof Schema]: Schema[key]['initialValue']; }; export declare class EasyForm<ValueType = any> extends EasyFormGenerator { /** * Reactivity of actual form is managed by angular reactive form */ formGroup: FormGroup; schema: FormSchema<ValueType>; options: EasyFormOptions; constructor(schema: FormSchema<ValueType>, options?: EasyFormOptions); get invalid(): boolean; get valid(): boolean; get value(): ValueType; get valueChanges(): Observable<ValueType>; /** * Create a new instance of EasyForm * @param schema * @param options */ static create<T = any>(schema: FormSchema<T>, options?: EasyFormOptions): EasyForm<T>; /** * Traverse through schema and get definition * @param path */ getSchema(path: string | Array<string | number>): EasyFormField<any> | FormSchema<any> | null; /** * Disable all form */ disable(): void; /** * Enable all form */ enable(): void; getComponentType(type: BasicControlTypes | string): EasyFormControlComponent | LazyLoadingComponent | null; getControl<ControlType = FormControl>(path: string | Array<string | number>): ControlType; getArrayControls(path: string | Array<string | number>): FormControl<any>[]; getValue<ValueType = any>(path?: string | Array<string | number>): ValueType; getRawValue<ValueType = any>(path?: string | Array<string | number>): ValueType; setValue(value: any, path?: string | Array<string | number>): void; patchValue(value: any, path?: string | Array<string | number>): void; addToArray(path: string, value: any): void; removeFromArray(path: string, index: any): void; private createFormGroup; private createFormArray; private createSimpleFormArray; private createValidations; private _getSchemaWithPath; }