diff --git a/packages/dnb-eufemia/src/extensions/forms/Field/PostalCodeAndCity/__tests__/PostalCodeAndCity.test.tsx b/packages/dnb-eufemia/src/extensions/forms/Field/PostalCodeAndCity/__tests__/PostalCodeAndCity.test.tsx
index b8df3d1f6cd..1708ffde760 100644
--- a/packages/dnb-eufemia/src/extensions/forms/Field/PostalCodeAndCity/__tests__/PostalCodeAndCity.test.tsx
+++ b/packages/dnb-eufemia/src/extensions/forms/Field/PostalCodeAndCity/__tests__/PostalCodeAndCity.test.tsx
@@ -240,6 +240,34 @@ describe('Field.PostalCodeAndCity', () => {
expect(postalCodeNo).toHaveAttribute('aria-placeholder', '0000')
})
+ it('should use value from country inside iterate', async () => {
+ render(
+
+
+
+
+
+ )
+
+ const [norway, germany] = Array.from(
+ document.querySelectorAll('.dnb-forms-field-postal-code-and-city')
+ )
+
+ await userEvent.type(
+ norway.querySelector('input'),
+ '{Backspace>4}987654'
+ )
+ expect(norway.querySelector('input').value).toBe('9876')
+
+ await userEvent.type(
+ germany.querySelector('input'),
+ '{Backspace>4}987654'
+ )
+ expect(germany.querySelector('input').value).toBe('987654')
+ })
+
describe('ARIA', () => {
const props = {
postalCode: { required: true, validateInitially: true },
diff --git a/packages/dnb-eufemia/src/extensions/forms/hooks/useDataValue.ts b/packages/dnb-eufemia/src/extensions/forms/hooks/useDataValue.ts
index 2371afe13b2..74a772bb7a7 100644
--- a/packages/dnb-eufemia/src/extensions/forms/hooks/useDataValue.ts
+++ b/packages/dnb-eufemia/src/extensions/forms/hooks/useDataValue.ts
@@ -2,6 +2,7 @@ import { useCallback, useContext, useRef } from 'react'
import pointer from '../utils/json-pointer'
import { Path } from '../types'
import DataContext, { ContextState } from '../DataContext/Context'
+import IterateItemContext from '../Iterate/IterateItemContext'
import usePath from './usePath'
export type Props = {
@@ -16,7 +17,8 @@ export default function useDataValue({
value,
}: Props = {}) {
const dataContextRef = useRef()
- dataContextRef.current = useContext(DataContext)
+ dataContextRef.current = useContext(DataContext)
+ const iterateItemContext = useContext(IterateItemContext)
const { makePath, makeIteratePath } = usePath()
@@ -76,12 +78,16 @@ export default function useDataValue({
const getSourceValue = useCallback(
(source: Path | Value) => {
if (typeof source === 'string' && isPath(source)) {
+ if (iterateItemContext) {
+ return getValueByIteratePath(source)
+ }
+
return getValueByPath(source)
}
return source
},
- [getValueByPath]
+ [getValueByIteratePath, getValueByPath, iterateItemContext]
)
if (pathProp) {