Skip to content

Commit

Permalink
Fix initialValue is ignored in children of ArrayInput
Browse files Browse the repository at this point in the history
Closes #4709
  • Loading branch information
fzaninotto committed May 13, 2020
1 parent 70e9b48 commit 89dd5b5
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion packages/ra-core/src/form/useInitializeFormWithRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand Down

0 comments on commit 89dd5b5

Please sign in to comment.