diff --git a/src/form/controlledInput.tsx b/src/form/controlledInput.tsx index fbc1af0..787e958 100644 --- a/src/form/controlledInput.tsx +++ b/src/form/controlledInput.tsx @@ -42,6 +42,7 @@ interface BaseProps { informations: Informations, deactivateReactMemo: boolean, inputWrapper?: (props: object) => JSX.Element, + defaultFormValue: any } interface ComponentProps extends BaseProps { @@ -55,7 +56,7 @@ interface ChildrenProps extends BaseProps { type Props = ComponentProps | ChildrenProps export const ControlledInput = (inputProps: Props) => { - const { step, entry, realEntry, children, component, errorDisplayed = false, informations, deactivateReactMemo, inputWrapper } = inputProps; + const { step, entry, realEntry, children, component, errorDisplayed = false, informations, deactivateReactMemo, inputWrapper, defaultFormValue } = inputProps; const { field } = useController({ defaultValue: isDefined(step.defaultValue) ? step.defaultValue : null, name: entry @@ -68,7 +69,7 @@ export const ControlledInput = (inputProps: Props) => { const functionalProperty = (entry: string, prop: any) => { if (typeof prop === 'function') { - return prop({ rawValues: getValues(), value: getValues(entry), informations, error, getValue: (key: string) => getValues(key) }); + return prop({ rawValues: getValues(), value: getValues(entry), defaultFormValue, informations, error, getValue: (key: string) => getValues(key) }); } else { return prop; } diff --git a/src/form/form.tsx b/src/form/form.tsx index 29a7f7c..8ca5f2a 100644 --- a/src/form/form.tsx +++ b/src/form/form.tsx @@ -31,7 +31,7 @@ type FormProps = { export interface FormRef { handleSubmit: () => void, trigger: () => void, - methods: UseFormReturn & { data: () => any} + methods: UseFormReturn & { data: () => any } } const FormComponent = (props: FormProps, ref: React.Ref) => { @@ -95,7 +95,7 @@ const FormComponent = (props: FormProps, ref: React.Re const functionalProperty = (entry: string, prop: T | ((param: { rawValues: { [x: string]: any }, value: any, informations?: Informations, getValue: (key: string) => any }) => T), informations?: Informations, error?: { [x: string]: any }): T => { if (typeof prop === 'function') { - return (prop as Function)({ rawValues: getValues(), value: getValues(entry), informations, getValue: (key: string) => getValues(key), error }); + return (prop as Function)({ rawValues: getValues(), value: getValues(entry), defaultFormValue: value, informations, getValue: (key: string) => getValues(key), error }); } else { return prop; } @@ -137,7 +137,8 @@ const FormComponent = (props: FormProps, ref: React.Re inputWrapper={inputWrapper} httpClient={maybeCustomHttpClient} functionalProperty={functionalProperty} - stepsOptions={{addLabel: props.options?.actions?.add?.label}} + stepsOptions={{ addLabel: props.options?.actions?.add?.label }} + defaultFormValue={value} /> ) } @@ -151,10 +152,10 @@ const FormComponent = (props: FormProps, ref: React.Re const informations = { path: entry, key: entry } return ( - + informations={informations} options={{ addLabel: props.options?.actions?.add?.label }} /> ) })}