The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
fix(record-form): block submission when field input has validation error (#28425)
Mahmoud Ghazyce4532cc4c48
diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/form-types/components/FormNumberFieldInput.tsx b/packages/twenty-front/src/modules/object-record/record-field/ui/form-types/components/FormNumberFieldInput.tsxindex 65eaa1ecece..243c5ab0050 100644--- a/packages/twenty-front/src/modules/object-record/record-field/ui/form-types/components/FormNumberFieldInput.tsx+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/form-types/components/FormNumberFieldInput.tsx@@ -153,7 +153,11 @@ export const FormNumberFieldInput = ({</FormFieldInputRowContainer>{hint ? <Field.Description>{hint}</Field.Description> : null}- {error && <Field.Error match>{error}</Field.Error>}+ {error && (+ <Field.Error match role="alert">+ {error}+ </Field.Error>+ )}</FormFieldInputContainer>);};diff --git a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormCurrencyFieldInput.tsx b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormCurrencyFieldInput.tsxindex 3e231ab0db6..2d8cf908466 100644--- a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormCurrencyFieldInput.tsx+++ b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormCurrencyFieldInput.tsx@@ -2,8 +2,10 @@ import {type FieldCurrencyValue,type FormFieldCurrencyValue,} from '@/object-record/record-field/ui/types/FieldMetadata';+import { recordFieldInputIsFieldInErrorComponentState } from '@/object-record/record-field/ui/states/recordFieldInputIsFieldInErrorComponentState';import { RecordFormTextInput } from '@/object-record/record-form/components/RecordFormTextInput';import { CurrencyPickerDropdownButton } from '@/ui/input/components/internal/currency/components/CurrencyPickerDropdownButton';+import { useSetAtomComponentState } from '@/ui/utilities/state/jotai/hooks/useSetAtomComponentState';import { t } from '@lingui/core/macro';import { isNonEmptyString } from '@sniptt/guards';import { useState } from 'react';@@ -35,6 +37,10 @@ export const RecordFormCurrencyFieldInput = ({readonly,placeholder,}: RecordFormCurrencyFieldInputProps) => {+ const setRecordFieldInputIsFieldInError = useSetAtomComponentState(+ recordFieldInputIsFieldInErrorComponentState,+ );+const amountMicros = defaultValue?.amountMicros ?? null;const [currencyCode, setCurrencyCode] = useState<CurrencyCode>(@@ -73,10 +79,12 @@ export const RecordFormCurrencyFieldInput = ({if (!canBeCastAsNumberOrNull(trimmedAmountText)) {setErrorMessage(t`Invalid number`);+ setRecordFieldInputIsFieldInError(true);return;}setErrorMessage(undefined);+ setRecordFieldInputIsFieldInError(false);const amount = castAsNumberOrNull(trimmedAmountText);diff --git a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormFieldInput.tsx b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormFieldInput.tsxindex 63436cc86bc..7253aa2e19d 100644--- a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormFieldInput.tsx+++ b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormFieldInput.tsx@@ -1,6 +1,7 @@import { FormFieldInput } from '@/object-record/record-field/ui/components/FormFieldInput';import { FormEmailsFieldInput } from '@/object-record/record-field/ui/form-types/components/FormEmailsFieldInput';import { FormLinksFieldInput } from '@/object-record/record-field/ui/form-types/components/FormLinksFieldInput';+import { recordFieldInputIsFieldInErrorComponentState } from '@/object-record/record-field/ui/states/recordFieldInputIsFieldInErrorComponentState';import { type FormFieldInputSubFieldPlaceholders } from '@/object-record/record-field/ui/form-types/types/FormFieldInputSubFieldPlaceholders';import { type FieldDefinition } from '@/object-record/record-field/ui/types/FieldDefinition';import { type FieldMetadata } from '@/object-record/record-field/ui/types/FieldMetadata';@@ -21,6 +22,7 @@ import { RecordFormCurrencyFieldInput } from '@/object-record/record-form/componimport { RecordFormPercentageFieldInput } from '@/object-record/record-form/components/RecordFormPercentageFieldInput';import { RecordFormPhoneFieldInput } from '@/object-record/record-form/components/RecordFormPhoneFieldInput';import { getRecordFormCurrencyFieldDefaultValue } from '@/object-record/record-form/utils/getRecordFormCurrencyFieldDefaultValue';+import { useSetAtomComponentState } from '@/ui/utilities/state/jotai/hooks/useSetAtomComponentState';import { isNonEmptyString } from '@sniptt/guards';import { type JsonValue } from 'type-fest';import { stripSimpleQuotesFromString } from '~/utils/string/stripSimpleQuotesFromString';@@ -47,6 +49,10 @@ export const RecordFormFieldInput = ({placeholder,subFieldPlaceholders,}: RecordFormFieldInputProps) => {+ const setRecordFieldInputIsFieldInError = useSetAtomComponentState(+ recordFieldInputIsFieldInErrorComponentState,+ );+if (isFieldLinks(field)) {return (<FormLinksFieldInput@@ -147,6 +153,9 @@ export const RecordFormFieldInput = ({defaultValue={defaultValue}onChange={onChange}onClear={onClear}+ onError={(error) =>+ setRecordFieldInputIsFieldInError(isNonEmptyString(error))+ }readonly={readonly}placeholder={placeholder}subFieldPlaceholders={subFieldPlaceholders}diff --git a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormFieldInputs.tsx b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormFieldInputs.tsxindex 511eb6bfd7e..4c29d3cce3e 100644--- a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormFieldInputs.tsx+++ b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormFieldInputs.tsx@@ -2,11 +2,13 @@ import { type EnrichedObjectMetadataItem } from '@/object-metadata/types/Enricheimport { type FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem';import { formatFieldMetadataItemAsFieldDefinition } from '@/object-metadata/utils/formatFieldMetadataItemAsFieldDefinition';import { getFieldMetadataItemGqlFieldName } from '@/object-metadata/utils/getFieldMetadataItemGqlFieldName';+import { RecordFieldComponentInstanceContext } from '@/object-record/record-field/ui/states/contexts/RecordFieldComponentInstanceContext';import { RecordFormFieldInput } from '@/object-record/record-form/components/RecordFormFieldInput';import { RecordFormFieldInputsEffect } from '@/object-record/record-form/components/RecordFormFieldInputsEffect';import { getRecordFormBooleanFieldDefaultValue } from '@/object-record/record-form/utils/getRecordFormBooleanFieldDefaultValue';import { getRecordFormCurrencyFieldDefaultValue } from '@/object-record/record-form/utils/getRecordFormCurrencyFieldDefaultValue';import { getRecordFormFieldPlaceholders } from '@/object-record/record-form/utils/getRecordFormFieldPlaceholders';+import { getRecordFormFieldInputInstanceId } from '@/object-record/record-form/utils/getRecordFormFieldInputInstanceId';import { type ObjectRecord } from '@/object-record/types/ObjectRecord';import { type ValidationRuleViolation } from '@/validation-rules/types/ValidationRuleViolation';import { styled } from '@linaria/react';@@ -30,6 +32,7 @@ type RecordFormFieldInputsProps = {>;onFieldValueChange: (gqlFieldName: string, value: JsonValue) => void;onFieldValueClear: (gqlFieldName: string) => void;+ formInstanceId: string;};export const RecordFormFieldInputs = ({@@ -39,6 +42,7 @@ export const RecordFormFieldInputs = ({validationRuleViolationsByFieldMetadataId = {},onFieldValueChange,onFieldValueClear,+ formInstanceId,}: RecordFormFieldInputsProps) => {return (<>@@ -55,36 +59,48 @@ export const RecordFormFieldInputs = ({getRecordFormFieldPlaceholders(fieldMetadataItem.type);return (- <Field.Root key={fieldMetadataItem.id}>- <RecordFormFieldInput- field={formatFieldMetadataItemAsFieldDefinition({- field: fieldMetadataItem,- objectMetadataItem,- showLabel: true,- })}- defaultValue={- Object.hasOwn(draftRecord, gqlFieldName)- ? draftRecord[gqlFieldName]- : (getRecordFormCurrencyFieldDefaultValue(- fieldMetadataItem,- ) ??- getRecordFormBooleanFieldDefaultValue(fieldMetadataItem))- }- onChange={(value) => onFieldValueChange(gqlFieldName, value)}- onClear={() => onFieldValueClear(gqlFieldName)}- placeholder={placeholder}- subFieldPlaceholders={subFieldPlaceholders}- />- {(- validationRuleViolationsByFieldMetadataId[- fieldMetadataItem.id- ] ?? []- ).map((violation) => (- <Field.Error key={violation.ruleId} match role="alert">- {violation.message}- </Field.Error>- ))}- </Field.Root>+ <RecordFieldComponentInstanceContext.Provider+ key={fieldMetadataItem.id}+ value={{+ instanceId: getRecordFormFieldInputInstanceId({+ formInstanceId,+ fieldMetadataId: fieldMetadataItem.id,+ }),+ }}+ >+ <Field.Root>+ <RecordFormFieldInput+ field={formatFieldMetadataItemAsFieldDefinition({+ field: fieldMetadataItem,+ objectMetadataItem,+ showLabel: true,+ })}+ defaultValue={+ Object.hasOwn(draftRecord, gqlFieldName)+ ? draftRecord[gqlFieldName]+ : (getRecordFormCurrencyFieldDefaultValue(+ fieldMetadataItem,+ ) ??+ getRecordFormBooleanFieldDefaultValue(+ fieldMetadataItem,+ ))+ }+ onChange={(value) => onFieldValueChange(gqlFieldName, value)}+ onClear={() => onFieldValueClear(gqlFieldName)}+ placeholder={placeholder}+ subFieldPlaceholders={subFieldPlaceholders}+ />+ {(+ validationRuleViolationsByFieldMetadataId[+ fieldMetadataItem.id+ ] ?? []+ ).map((violation) => (+ <Field.Error key={violation.ruleId} match role="alert">+ {violation.message}+ </Field.Error>+ ))}+ </Field.Root>+ </RecordFieldComponentInstanceContext.Provider>);})}</StyledFieldList>diff --git a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormPercentageFieldInput.tsx b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormPercentageFieldInput.tsxindex ef4a106aeb1..1d9b8f6e8e7 100644--- a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormPercentageFieldInput.tsx+++ b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormPercentageFieldInput.tsx@@ -1,8 +1,10 @@import { getNumberValueToPersist } from '@/object-record/record-field/ui/meta-types/input/utils/getNumberValueToPersist';+import { recordFieldInputIsFieldInErrorComponentState } from '@/object-record/record-field/ui/states/recordFieldInputIsFieldInErrorComponentState';import { type FieldDefinition } from '@/object-record/record-field/ui/types/FieldDefinition';import { type FieldNumberMetadata } from '@/object-record/record-field/ui/types/FieldMetadata';import { computeDraftValueFromFieldValue } from '@/object-record/record-field/ui/utils/computeDraftValueFromFieldValue';import { RecordFormTextInput } from '@/object-record/record-form/components/RecordFormTextInput';+import { useSetAtomComponentState } from '@/ui/utilities/state/jotai/hooks/useSetAtomComponentState';import { t } from '@lingui/core/macro';import { useState } from 'react';import { doNotTranslate } from 'twenty-shared/i18n';@@ -23,6 +25,9 @@ export const RecordFormPercentageFieldInput = ({onChange,readonly,}: RecordFormPercentageFieldInputProps) => {+ const setRecordFieldInputIsFieldInError = useSetAtomComponentState(+ recordFieldInputIsFieldInErrorComponentState,+ );const [inputText, setInputText] = useState(String(computeDraftValueFromFieldValue({@@ -47,10 +52,12 @@ export const RecordFormPercentageFieldInput = ({if (!percentageValueResult.success) {setErrorMessage(t`Invalid number`);+ setRecordFieldInputIsFieldInError(true);return;}setErrorMessage(undefined);+ setRecordFieldInputIsFieldInError(false);onChange(percentageValueResult.value);};diff --git a/packages/twenty-front/src/modules/object-record/record-form/components/__stories__/RecordFormFieldInputs.stories.tsx b/packages/twenty-front/src/modules/object-record/record-form/components/__stories__/RecordFormFieldInputs.stories.tsxindex 4c14d64c923..d8caf4909ed 100644--- a/packages/twenty-front/src/modules/object-record/record-form/components/__stories__/RecordFormFieldInputs.stories.tsx+++ b/packages/twenty-front/src/modules/object-record/record-form/components/__stories__/RecordFormFieldInputs.stories.tsx@@ -75,6 +75,7 @@ const RecordFormFieldInputsWithDraft = ({<RecordFormFieldInputsobjectMetadataItem={companyObjectMetadataItem}fieldMetadataItems={fieldMetadataItems}+ formInstanceId="record-form-story"draftRecord={draftRecord}onFieldValueChange={(gqlFieldName, value) =>writeDraft({ gqlFieldName, value })diff --git a/packages/twenty-front/src/modules/object-record/record-form/components/__tests__/RecordFormFieldInputs.test.tsx b/packages/twenty-front/src/modules/object-record/record-form/components/__tests__/RecordFormFieldInputs.test.tsxindex 105353d9dff..925f15b25eb 100644--- a/packages/twenty-front/src/modules/object-record/record-form/components/__tests__/RecordFormFieldInputs.test.tsx+++ b/packages/twenty-front/src/modules/object-record/record-form/components/__tests__/RecordFormFieldInputs.test.tsx@@ -38,6 +38,7 @@ const renderInputs = (draftRecord={draftRecord}onFieldValueChange={onFieldValueChange}onFieldValueClear={jest.fn()}+ formInstanceId="record-form"/>,);@@ -98,6 +99,7 @@ describe('RecordFormFieldInputs', () => {draftRecord={{}}onFieldValueChange={onFieldValueChange}onFieldValueClear={jest.fn()}+ formInstanceId="record-form"/>,);@@ -110,6 +112,7 @@ describe('RecordFormFieldInputs', () => {draftRecord={{}}onFieldValueChange={onFieldValueChange}onFieldValueClear={jest.fn()}+ formInstanceId="record-form"/>,);diff --git a/packages/twenty-front/src/modules/object-record/record-form/utils/getRecordFormFieldInputInstanceId.ts b/packages/twenty-front/src/modules/object-record/record-form/utils/getRecordFormFieldInputInstanceId.tsnew file mode 100644index 00000000000..70d5bed3261--- /dev/null+++ b/packages/twenty-front/src/modules/object-record/record-form/utils/getRecordFormFieldInputInstanceId.ts@@ -0,0 +1,7 @@+export const getRecordFormFieldInputInstanceId = ({+ formInstanceId,+ fieldMetadataId,+}: {+ formInstanceId: string;+ fieldMetadataId: string;+}) => `record-form-${formInstanceId}-${fieldMetadataId}`;diff --git a/packages/twenty-front/src/modules/object-record/record-update-multiple/components/UpdateMultipleRecordsForm.tsx b/packages/twenty-front/src/modules/object-record/record-update-multiple/components/UpdateMultipleRecordsForm.tsxindex 2f49f0c49cd..2a514e727e0 100644--- a/packages/twenty-front/src/modules/object-record/record-update-multiple/components/UpdateMultipleRecordsForm.tsx+++ b/packages/twenty-front/src/modules/object-record/record-update-multiple/components/UpdateMultipleRecordsForm.tsx@@ -1,11 +1,14 @@import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';import { formatFieldMetadataItemAsFieldDefinition } from '@/object-metadata/utils/formatFieldMetadataItemAsFieldDefinition';+import { RecordFieldComponentInstanceContext } from '@/object-record/record-field/ui/states/contexts/RecordFieldComponentInstanceContext';import { RecordFormFieldInput } from '@/object-record/record-form/components/RecordFormFieldInput';+import { getRecordFormFieldInputInstanceId } from '@/object-record/record-form/utils/getRecordFormFieldInputInstanceId';import { isFieldRelation } from '@/object-record/record-field/ui/types/guards/isFieldRelation';import { type UpdateMultipleRecordsState } from '@/object-record/record-update-multiple/components/UpdateMultipleRecordsContainer';import { isUpdateRecordValueEmpty } from '@/object-record/record-update-multiple/utils/isUpdateRecordValueEmpty';import { shouldDisplayFormMultiEditField } from '@/object-record/record-update-multiple/utils/shouldDisplayFormMultiEditField';import { css } from '@linaria/core';+import { useId } from 'react';import { FieldMetadataType } from 'twenty-shared/types';import { computeRelationGqlFieldJoinColumnName } from 'twenty-shared/utils';import { Section } from 'twenty-ui/components/layout';@@ -34,6 +37,7 @@ export const UpdateMultipleRecordsForm = ({const { objectMetadataItem } = useObjectMetadataItem({objectNameSingular,});+ const formInstanceId = useId();const editableFields = objectMetadataItem.fields.filter(shouldDisplayFormMultiEditField)@@ -77,14 +81,23 @@ export const UpdateMultipleRecordsForm = ({};return (- <RecordFormFieldInput+ <RecordFieldComponentInstanceContext.Providerkey={fieldDefinition.metadata.fieldName}- readonly={disabled}- field={fieldDefinition}- defaultValue={value}- onChange={handleValueChange}- onClear={() => onChange(fieldNameOrRelationIdName, undefined)}- />+ value={{+ instanceId: getRecordFormFieldInputInstanceId({+ formInstanceId,+ fieldMetadataId: fieldMetadataItem.id,+ }),+ }}+ >+ <RecordFormFieldInput+ readonly={disabled}+ field={fieldDefinition}+ defaultValue={value}+ onChange={handleValueChange}+ onClear={() => onChange(fieldNameOrRelationIdName, undefined)}+ />+ </RecordFieldComponentInstanceContext.Provider>);})}</Section.Root>diff --git a/packages/twenty-front/src/modules/side-panel/pages/record-creation-form/components/SidePanelRecordCreationFormPage.tsx b/packages/twenty-front/src/modules/side-panel/pages/record-creation-form/components/SidePanelRecordCreationFormPage.tsxindex f1c09cec8b8..4d5ecafdff5 100644--- a/packages/twenty-front/src/modules/side-panel/pages/record-creation-form/components/SidePanelRecordCreationFormPage.tsx+++ b/packages/twenty-front/src/modules/side-panel/pages/record-creation-form/components/SidePanelRecordCreationFormPage.tsx@@ -11,10 +11,12 @@ import { useObjectMetadataItemById } from '@/object-metadata/hooks/useObjectMetaimport { useObjectMetadataItems } from '@/object-metadata/hooks/useObjectMetadataItems';import { getFieldPermissions } from '@/object-metadata/utils/getFieldPermissions';import { useObjectPermissionsForObject } from '@/object-record/hooks/useObjectPermissionsForObject';+import { recordFieldInputIsFieldInErrorComponentState } from '@/object-record/record-field/ui/states/recordFieldInputIsFieldInErrorComponentState';import { RecordFormFieldInputs } from '@/object-record/record-form/components/RecordFormFieldInputs';import { useRecordCreationFormSettle } from '@/object-record/record-form/hooks/useRecordCreationFormSettle';import { useRecordFormFields } from '@/object-record/record-form/hooks/useRecordFormFields';import { computeRecordFormCreateRecordInput } from '@/object-record/record-form/utils/computeRecordFormCreateRecordInput';+import { getRecordFormFieldInputInstanceId } from '@/object-record/record-form/utils/getRecordFormFieldInputInstanceId';import { type ObjectRecord } from '@/object-record/types/ObjectRecord';import { useHasPermissionFlag } from '@/settings/roles/hooks/useHasPermissionFlag';import { useOpenRecordCreationFormSettingsInSidePanel } from '@/side-panel/hooks/useOpenRecordCreationFormSettingsInSidePanel';@@ -30,6 +32,7 @@ import { getValidationRuleViolationsFromError } from '@/validation-rules/utils/gimport { groupValidationRuleViolationsByField } from '@/validation-rules/utils/groupValidationRuleViolationsByField';import { useAtomComponentState } from '@/ui/utilities/state/jotai/hooks/useAtomComponentState';import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';+import { useStore } from 'jotai';import { useId, useState } from 'react';import { flushSync } from 'react-dom';import { styled } from '@linaria/react';@@ -115,6 +118,7 @@ const SidePanelRecordCreationForm = ({const { objectMetadataItems } = useObjectMetadataItems();const theme = useTheme();+ const store = useStore();const { settleRecordCreationDraft } = useRecordCreationFormSettle();const { enqueueToast } = useToast();@@ -131,6 +135,8 @@ const SidePanelRecordCreationForm = ({const [isSubmitting, setIsSubmitting] = useState(false);const [formResetCount, setFormResetCount] = useState(0);const contentId = useId();+ const formMountId = useId();+ const formInstanceId = `${formMountId}-${formResetCount}`;const optionsDropdownId = useId();const [draftValidationRuleViolations, setDraftValidationRuleViolations] =useState<ValidationRuleViolation[]>([]);@@ -171,18 +177,20 @@ const SidePanelRecordCreationForm = ({const hiddenFieldsCount = hiddenFieldMetadataItems.length;const editableFieldsCount = editableRecordFormFields.length;+ const displayedFieldMetadataItems = [+ ...visibleFieldMetadataItems,+ ...(recordCreationFormAreHiddenFieldsShown ? hiddenFieldMetadataItems : []),+ ];+const { violationsByFieldMetadataId, recordViolations } =groupValidationRuleViolationsByField({violations: [...draftValidationRuleViolations,...serverValidationRuleViolations,],- displayedFieldMetadataIds: [- ...visibleFieldMetadataItems,- ...(recordCreationFormAreHiddenFieldsShown- ? hiddenFieldMetadataItems- : []),- ].map((fieldMetadataItem) => fieldMetadataItem.id),+ displayedFieldMetadataIds: displayedFieldMetadataItems.map(+ (fieldMetadataItem) => fieldMetadataItem.id,+ ),});const computeViolations = (draftRecordToCheck: Partial<ObjectRecord>) =>@@ -218,6 +226,27 @@ const SidePanelRecordCreationForm = ({updateDraftRecord(gqlFieldName, null);};+ const getFieldInputIsInErrorAtom = (fieldMetadataId: string) =>+ recordFieldInputIsFieldInErrorComponentState.atomFamily({+ instanceId: getRecordFormFieldInputInstanceId({+ formInstanceId,+ fieldMetadataId,+ }),+ });++ const handleHiddenFieldsToggleClick = () => {+ // Collapsed inputs unmount and come back without their error text, so drop their error state too.+ if (recordCreationFormAreHiddenFieldsShown) {+ for (const fieldMetadataItem of hiddenFieldMetadataItems) {+ store.set(getFieldInputIsInErrorAtom(fieldMetadataItem.id), false);+ }+ }++ setRecordCreationFormAreHiddenFieldsShown(+ !recordCreationFormAreHiddenFieldsShown,+ );+ };+const revealHiddenFieldsIfTargeted = (targetedFieldMetadataIds: (string | null)[],) => {@@ -246,6 +275,16 @@ const SidePanelRecordCreationForm = ({return;}+ const isAnyDisplayedFieldInputInError = displayedFieldMetadataItems.some(+ (fieldMetadataItem) =>+ store.get(getFieldInputIsInErrorAtom(fieldMetadataItem.id)),+ );++ if (isAnyDisplayedFieldInputInError) {+ scrollToFirstFieldViolation();+ return;+ }+setServerValidationRuleViolations([]);if (validationRules.length > 0) {@@ -358,6 +397,7 @@ const SidePanelRecordCreationForm = ({}onFieldValueChange={handleFieldValueChange}onFieldValueClear={handleFieldValueClear}+ formInstanceId={formInstanceId}/>{hiddenFieldsCount > 0 && (<StyledHiddenFieldsToggle>@@ -369,11 +409,7 @@ const SidePanelRecordCreationForm = ({<IconChevronDown />)}- onClick={() =>- setRecordCreationFormAreHiddenFieldsShown(- !recordCreationFormAreHiddenFieldsShown,- )- }+ onClick={handleHiddenFieldsToggleClick}>{recordCreationFormAreHiddenFieldsShown? t`Hide fields`@@ -391,6 +427,7 @@ const SidePanelRecordCreationForm = ({}onFieldValueChange={handleFieldValueChange}onFieldValueClear={handleFieldValueClear}+ formInstanceId={formInstanceId}/>)}</StyledContent>diff --git a/packages/twenty-front/src/modules/side-panel/pages/record-creation-form/components/__tests__/SidePanelRecordCreationFormPage.test.tsx b/packages/twenty-front/src/modules/side-panel/pages/record-creation-form/components/__tests__/SidePanelRecordCreationFormPage.test.tsxindex a8041472ffb..37bdf19d961 100644--- a/packages/twenty-front/src/modules/side-panel/pages/record-creation-form/components/__tests__/SidePanelRecordCreationFormPage.test.tsx+++ b/packages/twenty-front/src/modules/side-panel/pages/record-creation-form/components/__tests__/SidePanelRecordCreationFormPage.test.tsx@@ -160,6 +160,13 @@ jest.mock(createElement: typeof createElement;Fragment: typeof Fragment;};+ const jotaiStoreModuleForMock = require('@/ui/utilities/state/jotai/jotaiStore');+ const {+ recordFieldInputIsFieldInErrorComponentState: errorStateForMock,+ } = require('@/object-record/record-field/ui/states/recordFieldInputIsFieldInErrorComponentState');+ const {+ getRecordFormFieldInputInstanceId: getInstanceIdForMock,+ } = require('@/object-record/record-form/utils/getRecordFormFieldInputInstanceId');return {RecordFormFieldInputs: ({@@ -167,6 +174,7 @@ jest.mock(draftRecord,validationRuleViolationsByFieldMetadataId = {},onFieldValueChange,+ formInstanceId,}: {fieldMetadataItems: { id: string; name: string; label: string }[];draftRecord: Record<string, unknown>;@@ -175,6 +183,7 @@ jest.mock({ ruleId: string; message: string }[]>;onFieldValueChange: (gqlFieldName: string, value: string) => void;+ formInstanceId: string;}) =>ReactForMock.createElement(ReactForMock.Fragment,@@ -190,11 +199,21 @@ jest.mock(ReactForMock.createElement('input', {'aria-label': fieldMetadataItem.label,value: (draftRecord[fieldMetadataItem.name] as string) ?? '',- onChange: (event: { target: { value: string } }) =>+ onChange: (event: { target: { value: string } }) => {onFieldValueChange(fieldMetadataItem.name,event.target.value,- ),+ );+ jotaiStoreModuleForMock.jotaiStore.set(+ errorStateForMock.atomFamily({+ instanceId: getInstanceIdForMock({+ formInstanceId,+ fieldMetadataId: fieldMetadataItem.id,+ }),+ }),+ event.target.value === 'invalid',+ );+ },}),(validationRuleViolationsByFieldMetadataId[@@ -566,4 +585,40 @@ describe('SidePanelRecordCreationFormPage', () => {screen.queryByRole('button', { name: 'Hide fields' }),).not.toBeInTheDocument();});++ it('does not submit when a field input reports a validation error', async () => {+ const user = userEvent.setup();++ renderPage();++ await user.type(screen.getByLabelText('Name'), 'invalid');+ await user.click(screen.getByTestId('record-creation-form-create-button'));++ expect(settleRecordCreationDraft).not.toHaveBeenCalled();++ await user.clear(screen.getByLabelText('Name'));+ await user.type(screen.getByLabelText('Name'), 'Valid Name');+ await user.click(screen.getByTestId('record-creation-form-create-button'));++ expect(settleRecordCreationDraft).toHaveBeenCalledTimes(1);+ expect(settleRecordCreationDraft).toHaveBeenCalledWith({+ requestId: REQUEST_ID,+ draftRecord: { name: 'Valid Name' },+ shouldKeepOpen: false,+ });+ });++ it('stops blocking creation once a hidden field with an input error is collapsed and shown again', async () => {+ const user = userEvent.setup();++ renderPage();++ await user.click(screen.getByRole('button', { name: 'All fields (3)' }));+ await user.type(screen.getByLabelText('Nickname'), 'invalid');+ await user.click(screen.getByRole('button', { name: 'Hide fields' }));+ await user.click(screen.getByRole('button', { name: 'All fields (3)' }));+ await user.click(screen.getByTestId('record-creation-form-create-button'));++ expect(settleRecordCreationDraft).toHaveBeenCalledTimes(1);+ });});