Skip to content

Commit

Permalink
Fix initialValue is ignored in children of ArrayInput
Browse files Browse the repository at this point in the history
  • Loading branch information
fzaninotto authored and asvarcas committed May 22, 2020
1 parent 8473ad4 commit e5eb212
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 e5eb212

Please sign in to comment.