Update packages/features/form-builder/FormBuilder.tsx
Co-authored-by: Omar López <zomars@me.com>pull/6560/head
parent
7316bd4775
commit
10d9886dcc
|
@ -542,25 +542,16 @@ export const ComponentForField = ({
|
||||||
const componentConfig = Components[fieldType];
|
const componentConfig = Components[fieldType];
|
||||||
|
|
||||||
const isValueOfPropsType = (val: unknown, propsType: typeof componentConfig.propsType) => {
|
const isValueOfPropsType = (val: unknown, propsType: typeof componentConfig.propsType) => {
|
||||||
if (propsType === "text") {
|
const propsTypeConditionMap = {
|
||||||
return typeof val === "string";
|
boolean: typeof val === "boolean",
|
||||||
}
|
multiselect: val instanceof Array && val.every((v) => typeof v === "string"),
|
||||||
if (propsType === "boolean") {
|
objectiveWithInput: typeof val === "object" && val !== null ? "value" in val : false,
|
||||||
return typeof val === "boolean";
|
select: typeof val === "string",
|
||||||
}
|
text: typeof val === "string",
|
||||||
if (propsType === "textList") {
|
textList: val instanceof Array && val.every((v) => typeof v === "string"),
|
||||||
return val instanceof Array && val.every((v) => typeof v === "string");
|
} as const;
|
||||||
}
|
if (!propsTypeConditionMap[propsType]) throw new Error(`Unknown propsType ${propsType}`);
|
||||||
if (propsType === "select") {
|
return propsTypeConditionMap[propsType];
|
||||||
return typeof val === "string";
|
|
||||||
}
|
|
||||||
if (propsType === "multiselect") {
|
|
||||||
return val instanceof Array && val.every((v) => typeof v === "string");
|
|
||||||
}
|
|
||||||
if (propsType === "objectiveWithInput") {
|
|
||||||
return typeof value === "object" && value !== null ? "value" in value : false;
|
|
||||||
}
|
|
||||||
throw new Error(`Unknown propsType ${propsType}`);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// If possible would have wanted `isValueOfPropsType` to narrow the type of `value` and `setValue` accordingly, but can't seem to do it.
|
// If possible would have wanted `isValueOfPropsType` to narrow the type of `value` and `setValue` accordingly, but can't seem to do it.
|
||||||
|
|
Loading…
Reference in New Issue