diff options
Diffstat (limited to 'packages/merchant-backoffice-ui/src/components/form/InputSelector.tsx')
-rw-r--r-- | packages/merchant-backoffice-ui/src/components/form/InputSelector.tsx | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/packages/merchant-backoffice-ui/src/components/form/InputSelector.tsx b/packages/merchant-backoffice-ui/src/components/form/InputSelector.tsx index 021977dfe..495c93897 100644 --- a/packages/merchant-backoffice-ui/src/components/form/InputSelector.tsx +++ b/packages/merchant-backoffice-ui/src/components/form/InputSelector.tsx @@ -24,8 +24,7 @@ import { InputProps, useField } from "./useField.js"; interface Props<T> extends InputProps<T> { readonly?: boolean; expand?: boolean; - values: string[]; - convert?: (v: string) => any; + values: any[]; toStr?: (v?: any) => string; fromStr?: (s: string) => any; } @@ -42,11 +41,11 @@ export function InputSelector<T>({ label, help, values, - convert, + fromStr = defaultFromString, toStr = defaultToString, }: Props<keyof T>): VNode { const { error, value, onChange } = useField<T>(name); - + console.log(error); return ( <div class="field is-horizontal"> <div class="field-label is-normal"> @@ -68,18 +67,17 @@ export function InputSelector<T>({ disabled={readonly} readonly={readonly} onChange={(e) => { - const v = convert - ? convert(e.currentTarget.value) - : e.currentTarget.value; - onChange(v); + onChange(fromStr(e.currentTarget.value)); }} > {placeholder && <option>{placeholder}</option>} - {values.map((v, i) => ( - <option key={i} value={v} selected={value === v}> - {toStr(v)} - </option> - ))} + {values.map((v, i) => { + return ( + <option key={i} value={v} selected={value === v}> + {toStr(v)} + </option> + ); + })} </select> {help} </p> |