diff --git a/packages/sanity/src/core/form/store/formState.ts b/packages/sanity/src/core/form/store/formState.ts index 0968ab4db91..1cd71aaf3be 100644 --- a/packages/sanity/src/core/form/store/formState.ts +++ b/packages/sanity/src/core/form/store/formState.ts @@ -79,7 +79,7 @@ type PrepareFieldMember = (props: { field: ObjectField parent: FormStateOptions & { groups: FormFieldGroup[] - selectedGroup: FormFieldGroup + selectedGroup?: FormFieldGroup } index: number }) => ObjectMember | HiddenField | null @@ -117,8 +117,12 @@ function isFieldEnabledByGroupFilter( // the groups config for the "enclosing object" type groupsConfig: FormFieldGroup[], fieldGroup: string | string[] | undefined, - selectedGroup: FormFieldGroup, + selectedGroup: FormFieldGroup | undefined, ) { + if (!selectedGroup) { + return false + } + if (selectedGroup.name === ALL_FIELDS_GROUP.name) { return true } @@ -827,7 +831,7 @@ export function createPrepareFormState({ }, ) - const selectedGroup = groups.find((group) => group.selected)! + const selectedGroup = groups.find((group) => group.selected) // note: this is needed because not all object types gets a ´fieldsets´ property during schema parsing. // ideally members should be normalized as part of the schema parsing and not here