diff --git a/packages/ra-core/src/form/useInitializeFormWithRecord.ts b/packages/ra-core/src/form/useInitializeFormWithRecord.ts index 2dabc249777..5207b621301 100644 --- a/packages/ra-core/src/form/useInitializeFormWithRecord.ts +++ b/packages/ra-core/src/form/useInitializeFormWithRecord.ts @@ -9,14 +9,21 @@ const useInitializeFormWithRecord = (form, record) => { return; } + const registeredFields = form.getRegisteredFields(); + // react-final-form does not provide a way to set multiple values in one call. // Using batch ensure we don't get rerenders until all our values are set form.batch(() => { Object.keys(record).forEach(key => { - form.change(key, record[key]); + // We have to check the record key is actually registered as a field + // as some of record keys may not have a matching input + if (registeredFields.some(field => field === key)) { + form.change(key, record[key]); + form.resetFieldState(key); + } }); }); - }, []); // eslint-disable-line + }, [form, record]); }; export default useInitializeFormWithRecord;