From e5eb21259fac34b3b41cae30b333051132c54da6 Mon Sep 17 00:00:00 2001 From: fzaninotto Date: Wed, 13 May 2020 19:34:54 +0200 Subject: [PATCH] Fix initialValue is ignored in children of ArrayInput Closes #4709 --- .../src/form/useInitializeFormWithRecord.ts | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/ra-core/src/form/useInitializeFormWithRecord.ts b/packages/ra-core/src/form/useInitializeFormWithRecord.ts index febfb420926..189b3e439e7 100644 --- a/packages/ra-core/src/form/useInitializeFormWithRecord.ts +++ b/packages/ra-core/src/form/useInitializeFormWithRecord.ts @@ -21,7 +21,26 @@ const useInitializeFormWithRecord = record => { // We have to check the record key is actually registered as a field // as some record keys may not have a matching input if (registeredFields.some(field => field === key)) { - form.change(key, record[key]); + if (Array.isArray(record[key])) { + // array of values + record[key].forEach((value, index) => { + if (value && Object.keys(value).length > 0) { + // array of objects + Object.keys(value).forEach(key2 => { + form.change( + `${key}[${index}].${key2}`, + value[key2] + ); + }); + } else { + // array of scala values + form.change(`${key}[${index}]`, value); + } + }); + } else { + // scalar value + form.change(key, record[key]); + } form.resetFieldState(key); } });