Skip to content

Commit b0df7c0

Browse files
Merge pull request #289 from open-formulieren/issue/266-editgrid-with-addressnl
#226 bugfix of adressNL crashing inside the editgrid
2 parents 769167d + 7aef044 commit b0df7c0

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

src/registry/addressNL/deriveAddress.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {useFormikContext} from 'formik';
33
import {useEffect, useState} from 'react';
44
import {useAsync} from 'react-use';
55

6-
import {useDebounce, useFormSettings} from '@/hooks';
6+
import {useDebounce, useFieldConfig, useFormSettings} from '@/hooks';
77

88
import type {FormValues} from './types';
99
import {DEFAULT_POSTCODE_REGEX, HOUSE_NUMBER_REGEX} from './validationSchema';
@@ -20,6 +20,7 @@ const testValidInputs = (postcode: string, houseNumber: string): boolean => {
2020

2121
export const useDeriveAddress = (key: string, enabled: boolean): UseDeriveAddress => {
2222
const {getFieldProps, setFieldValue} = useFormikContext<FormValues>();
23+
key = useFieldConfig(key);
2324
const {value} = getFieldProps<AddressData>(key);
2425
const formSettings = useFormSettings();
2526
const [enableManualEntry, setEnableManualEntry] = useState<boolean>(false);

src/registry/editgrid/index.stories.ts

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ import {expect, fn, userEvent, waitFor, within} from 'storybook/test';
1010

1111
import FormioComponent from '@/components/FormioComponent';
1212
import type {FormioFormProps} from '@/components/FormioForm';
13+
import type {FormSettings} from '@/context';
1314
import {getRegistryEntry} from '@/registry';
1415
import {renderComponentInForm} from '@/registry/storybook-helpers';
15-
import {withFormik} from '@/sb-decorators';
16+
import {withFormSettingsProvider, withFormik} from '@/sb-decorators';
1617
import type {JSONObject} from '@/types';
1718

1819
import {FormioEditGrid} from './';
@@ -819,3 +820,60 @@ export const MutationsTriggerRevalidation: ValidationStory = {
819820
});
820821
},
821822
};
823+
824+
export const WithAdressNL: Story = {
825+
decorators: [withFormSettingsProvider, withFormik],
826+
args: {
827+
componentDefinition: {
828+
id: 'component1',
829+
type: 'editgrid',
830+
key: 'editgrid',
831+
label: 'Various combinations of value display',
832+
disableAddingRemovingRows: false,
833+
groupLabel: 'Nested item',
834+
components: [
835+
{
836+
id: 'addressNL',
837+
type: 'addressNL',
838+
key: 'addressNL',
839+
label: 'AddressNL',
840+
layout: 'singleColumn',
841+
deriveAddress: true,
842+
},
843+
],
844+
},
845+
},
846+
parameters: {
847+
formik: {
848+
initialValues: {
849+
editgrid: [
850+
{
851+
addressNL: {
852+
postcode: '1043GR',
853+
houseNumber: '151',
854+
houseLetter: 'A',
855+
houseNumberAddition: '9',
856+
streetName: 'Kingsfordweg',
857+
city: 'Amsterdam',
858+
} satisfies AddressData,
859+
},
860+
],
861+
},
862+
},
863+
formSettings: {
864+
componentParameters: {
865+
addressNL: {
866+
addressAutoComplete: async () => ({
867+
streetName: 'Autofilled street',
868+
city: 'Autofilled',
869+
secretStreetCity: 'some-hashed-security-thing',
870+
}),
871+
},
872+
} satisfies FormSettings['componentParameters'],
873+
},
874+
},
875+
play: async ({canvasElement}) => {
876+
const canvas = within(canvasElement);
877+
await userEvent.click(canvas.getByRole('button', {name: 'Edit item 1'}));
878+
},
879+
};

0 commit comments

Comments
 (0)