diff --git a/src/form/EntityForm.tsx b/src/form/EntityForm.tsx index 1264f253a..3648a0032 100644 --- a/src/form/EntityForm.tsx +++ b/src/form/EntityForm.tsx @@ -188,7 +188,7 @@ export function EntityForm({ previousValues: initialValues }), [schemaOrResolver, path, entityId, internalValue]); - const mustSetCustomId: boolean = (status === "new" || status === "copy") && !!schema.customId; + const mustSetCustomId: boolean = (status === "new" || status === "copy") && (!!schema.customId && schema.customId !== "optional"); const underlyingChanges: Partial> = useMemo(() => { if (initialValues && status === "existing") { @@ -225,7 +225,9 @@ export function EntityForm({ savedEntityId = entity.id; } else if (status === "new" || status === "copy") { if (schema.customId) { - if (!customId) throw Error("Form misconfiguration when saving, customId should be set"); + if (schema.customId !== "optional" && !customId) { + throw Error("Form misconfiguration when saving, customId should be set"); + } savedEntityId = customId; } } else { diff --git a/src/models/entities.ts b/src/models/entities.ts index bd523bad4..57e83357c 100644 --- a/src/models/entities.ts +++ b/src/models/entities.ts @@ -19,11 +19,12 @@ export interface EntitySchema { /** * If this property is not set, the property will be created by the * datasource. - * You can set the value to true to allow the users to choose the ID. + * You can set the value to 'true' to force the users to choose the ID. + * You can set the value to 'optional' to allow the users to choose the ID. If the ID is empty, an automatic ID will be set. * You can also pass a set of values (as an EnumValues object) to allow them * to pick from only those */ - customId?: boolean | EnumValues; + customId?: boolean | "optional" | EnumValues; /** * Set of properties that compose an entity