mirror of
https://github.com/zhigang1992/firecms.git
synced 2026-06-14 01:34:55 +08:00
Fix for table select fields with number as data types
This commit is contained in:
@@ -236,6 +236,7 @@ const TableCell = <T, S extends EntitySchema<Key>, 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 = <T, S extends EntitySchema<Key>, 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 = <T, S extends EntitySchema<Key>, Key extends string>({
|
||||
multiple={true}
|
||||
disabled={disabled}
|
||||
focused={focused}
|
||||
valueType={arrayProperty.of.dataType}
|
||||
enumValues={arrayProperty.of.config.enumValues}
|
||||
error={error}
|
||||
onBlur={onBlur}
|
||||
|
||||
@@ -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<HTMLInputElement | HTMLTextAreaElement>;
|
||||
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<boolean>(false);
|
||||
const handleOpen = () => {
|
||||
@@ -41,7 +52,6 @@ export function TableSelect(props: {
|
||||
// const ref = React.createRef<HTMLInputElement>();
|
||||
// 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]);
|
||||
|
||||
Reference in New Issue
Block a user