diff --git a/packages/ui/src/components/form/FormGroup.tsx b/packages/ui/src/components/form/FormGroup.tsx index e1f5b4c5..3e2d7eff 100644 --- a/packages/ui/src/components/form/FormGroup.tsx +++ b/packages/ui/src/components/form/FormGroup.tsx @@ -1,3 +1,4 @@ +import type { AbstractControl } from './abstract-control'; import type { FormGroup } from './form-group'; import React from 'react'; @@ -9,7 +10,7 @@ export const DFormGroupContext = React.createContext(null); export interface DFormGroupProps { children: React.ReactNode; - dFormGroup: FormGroup; + dFormGroup: AbstractControl; dTitle?: React.ReactNode; } @@ -18,7 +19,7 @@ export function DFormGroup(props: DFormGroupProps): JSX.Element | null { const { children, dFormGroup, dTitle } = useComponentConfig(COMPONENT_NAME, props); return ( - + {dTitle} {children} diff --git a/packages/ui/src/components/form/form-group.ts b/packages/ui/src/components/form/form-group.ts index d99170cb..0c98d9f0 100644 --- a/packages/ui/src/components/form/form-group.ts +++ b/packages/ui/src/components/form/form-group.ts @@ -21,6 +21,11 @@ type GetFormControlProperty = S extends `${infer K}.${infer R}` ? T[S] : any; +type GetFormGroupT> = C extends FormGroup ? T : unknown; +type GetFormGroupValue = { + [K in keyof T]?: T[K] extends FormGroup ? GetFormGroupValue> : T[K]['value']; +}; + function find(control: AbstractControl, path: string[] | string, delimiter: string) { if (path == null) return null; @@ -107,7 +112,7 @@ export class FormGroup exte }); this.updateValueAndValidity(onlySelf); } - override patchValue(value: { [K in keyof T]?: T[K]['value'] } & { [K: string]: any }, onlySelf?: boolean): void { + override patchValue(value: GetFormGroupValue & { [K: string]: any }, onlySelf?: boolean): void { Object.keys(value).forEach((name) => { if (this.controls[name]) { this.controls[name].patchValue(value[name], true); @@ -115,7 +120,7 @@ export class FormGroup exte }); this.updateValueAndValidity(onlySelf); } - override reset(value: { [K in keyof T]?: T[K]['value'] } & { [K: string]: any } = {}, onlySelf?: boolean): void { + override reset(value: GetFormGroupValue & { [K: string]: any } = {}, onlySelf?: boolean): void { this._forEachChild((control, name) => { control.reset(value[name], true); });