Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
djhi committed Sep 20, 2019
1 parent 3e56efe commit 7ecbc8a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions packages/ra-core/src/form/useInitializeFormWithRecord.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { useEffect } from 'react';
import { useForm } from 'react-final-form';

/**
* Restore the record values which should override any default values specified on the form.
*/
const useInitializeFormWithRecord = (form, record) => {
const useInitializeFormWithRecord = record => {
const form = useForm();

useEffect(() => {
if (!record) {
return;
Expand All @@ -16,7 +19,7 @@ const useInitializeFormWithRecord = (form, record) => {
form.batch(() => {
Object.keys(record).forEach(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
// as some record keys may not have a matching input
if (registeredFields.some(field => field === key)) {
form.change(key, record[key]);
form.resetFieldState(key);
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-ui-materialui/src/form/SimpleForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const SimpleFormView = ({
margin,
...rest
}) => {
useInitializeFormWithRecord(form, record);
useInitializeFormWithRecord(record);

const handleSubmitWithRedirect = useCallback(
(redirect = defaultRedirect) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-ui-materialui/src/form/TabbedForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export const TabbedFormView = ({
margin,
...rest
}) => {
useInitializeFormWithRecord(form, record);
useInitializeFormWithRecord(record);

const handleSubmitWithRedirect = useCallback(
(redirect = defaultRedirect) => {
Expand Down

0 comments on commit 7ecbc8a

Please sign in to comment.