From 3f574eb0c968229fcc2fb67b9a88c19c10e62fba Mon Sep 17 00:00:00 2001 From: francesco Date: Tue, 23 Feb 2021 13:19:29 +0100 Subject: [PATCH] Fix for table select fields with number as data types --- src/collection/TableCell.tsx | 3 +++ src/collection/fields/TableSelect.tsx | 26 +++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/collection/TableCell.tsx b/src/collection/TableCell.tsx index 8345a03..7692fc0 100644 --- a/src/collection/TableCell.tsx +++ b/src/collection/TableCell.tsx @@ -236,6 +236,7 @@ const TableCell = , Key extends string>({ multiple={false} disabled={disabled} focused={focused} + valueType={"number"} enumValues={numberProperty.config.enumValues} error={error} onBlur={onBlur} @@ -262,6 +263,7 @@ const TableCell = , Key extends string>({ multiple={false} focused={focused} disabled={disabled} + valueType={"string"} enumValues={stringProperty.config.enumValues} error={error} onBlur={onBlur} @@ -320,6 +322,7 @@ const TableCell = , Key extends string>({ multiple={true} disabled={disabled} focused={focused} + valueType={arrayProperty.of.dataType} enumValues={arrayProperty.of.config.enumValues} error={error} onBlur={onBlur} diff --git a/src/collection/fields/TableSelect.tsx b/src/collection/fields/TableSelect.tsx index ffd685d..26c6785 100644 --- a/src/collection/fields/TableSelect.tsx +++ b/src/collection/fields/TableSelect.tsx @@ -13,13 +13,24 @@ export function TableSelect(props: { multiple: boolean; disabled: boolean; internalValue: string | number | string[] | number[] | undefined; + valueType: "string" | "number"; updateValue: (newValue: (string | number | string[] | number[] | undefined)) => void; focused: boolean; onBlur?: React.FocusEventHandler; setPreventOutsideClick: (value: any) => void; }) { - const { name, enumValues, error, internalValue, disabled, updateValue, multiple, setPreventOutsideClick } = props; + const { + name, + enumValues, + error, + internalValue, + disabled, + updateValue, + multiple, + setPreventOutsideClick, + valueType + } = props; const [open, setOpen] = useState(false); const handleOpen = () => { @@ -41,7 +52,6 @@ export function TableSelect(props: { // const ref = React.createRef(); // useEffect(() => { // if (ref.current && focused) { - // console.log("select focus", ref.current); // ref.current?.focus({ preventScroll: true }); // } // }, [focused, ref.current]); @@ -69,7 +79,17 @@ export function TableSelect(props: { error={!!error} value={validValue ? internalValue : (multiple ? [] : "")} onChange={(evt) => { - updateValue(evt.target.value as typeof internalValue); + if (valueType === "number") { + if (multiple) { + updateValue((evt.target.value as string[]).map((v) => parseFloat(v))); + } else { + updateValue(parseFloat(evt.target.value as string)); + } + } else if (valueType === "string") { + updateValue(evt.target.value as typeof internalValue); + } else { + throw Error("Missing mapping in TableSelect"); + } }} renderValue={(selected: any) => { const label = buildEnumLabel(enumValues[selected]);