diff options
author | Sebastian <sebasjm@gmail.com> | 2024-04-29 15:31:14 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-04-29 15:31:14 -0300 |
commit | eeabe64b3f0ac02818561ea6fca364d619f061b7 (patch) | |
tree | c1cdf6f9a5ea9fa193153ee07c9f053432e2353a /packages/web-util/src/forms/useField.ts | |
parent | 50442d335e1332bbb2457bd02b973edff7845a31 (diff) | |
download | wallet-core-eeabe64b3f0ac02818561ea6fca364d619f061b7.tar.xz |
sync field ui
Diffstat (limited to 'packages/web-util/src/forms/useField.ts')
-rw-r--r-- | packages/web-util/src/forms/useField.ts | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/packages/web-util/src/forms/useField.ts b/packages/web-util/src/forms/useField.ts index fad53ebac..d30962c6f 100644 --- a/packages/web-util/src/forms/useField.ts +++ b/packages/web-util/src/forms/useField.ts @@ -1,11 +1,12 @@ -import { useContext, useState } from "preact/compat"; +import { useContext } from "preact/compat"; import { FieldUIOptions, FormContext } from "./FormProvider.js"; +import { TranslatedString } from "@gnu-taler/taler-util"; export interface InputFieldHandler<Type> { value: Type; onChange: (s: Type) => void; state: FieldUIOptions; - isDirty: boolean; + error?: TranslatedString | undefined; } /** @@ -33,8 +34,7 @@ export function useField<T extends object, K extends keyof T>( const formState = computeFormState ? computeFormState(formValue.current) : {}; const fieldValue = readField(formValue.current, String(name)) as V; - // console.log("USE FIELD", String(name), formValue.current, fieldValue); - // const [currentValue, setCurrentValue] = useState<any | undefined>(fieldValue); + const fieldState = readField<Partial<FieldUIOptions>>(formState, String(name)) ?? {}; @@ -42,7 +42,6 @@ export function useField<T extends object, K extends keyof T>( const state = { disabled: readOnlyForm ? true : (fieldState.disabled ?? false), hidden: fieldState.hidden ?? false, - error: fieldState.error, help: fieldState.help, elements: "elements" in fieldState ? fieldState.elements ?? [] : [], }; @@ -62,7 +61,6 @@ export function useField<T extends object, K extends keyof T>( return { value: fieldValue, onChange, - isDirty: fieldValue !== undefined, state, }; } |