Skip to content

Commit

Permalink
Merge pull request #4819 from alanpoulain/fix-initialize-form-array-o…
Browse files Browse the repository at this point in the history
…bjects

Fix useInitializeFormWithRecord with an array of objects
  • Loading branch information
fzaninotto committed May 18, 2020
2 parents 9d663fb + 810bd66 commit f383c7b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/ra-core/src/form/useInitializeFormWithRecord.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect } from 'react';
import { useForm } from 'react-final-form';
import { isObject } from '../inference/assertions';

/**
* Restore the record values which should override any default values specified on the form.
Expand All @@ -24,7 +25,10 @@ const useInitializeFormWithRecord = record => {
if (Array.isArray(record[key])) {
// array of values
record[key].forEach((value, index) => {
if (value && Object.keys(value).length > 0) {
if (
isObject(value) &&
Object.keys(value).length > 0
) {
// array of objects
Object.keys(value).forEach(key2 => {
form.change(
Expand Down

0 comments on commit f383c7b

Please sign in to comment.