From fb77e0677a13c3521a6d84d378663a52d14cece1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?An=C3=ADbal=20Svarcas?= Date: Tue, 29 Nov 2022 10:35:28 -0300 Subject: [PATCH 1/3] Remove warning --- .../ra-core/src/form/FormDataConsumer.tsx | 34 +------------------ 1 file changed, 1 insertion(+), 33 deletions(-) diff --git a/packages/ra-core/src/form/FormDataConsumer.tsx b/packages/ra-core/src/form/FormDataConsumer.tsx index 3f4d9668e89..8e1307bbf8f 100644 --- a/packages/ra-core/src/form/FormDataConsumer.tsx +++ b/packages/ra-core/src/form/FormDataConsumer.tsx @@ -57,49 +57,17 @@ const FormDataConsumer = (props: ConnectedProps) => { export const FormDataConsumerView = (props: Props) => { const { children, form, formData, source, index, ...rest } = props; - let getSourceHasBeenCalled = false; let ret; // If we have an index, we are in an iterator like component (such as the SimpleFormIterator) if (typeof index !== 'undefined' && source) { const scopedFormData = get(formData, source); - const getSource = (scopedSource: string) => { - getSourceHasBeenCalled = true; - return `${source}.${scopedSource}`; - }; + const getSource = (scopedSource: string) => `${source}.${scopedSource}`; ret = children({ formData, scopedFormData, getSource, ...rest }); } else { ret = children({ formData, ...rest }); } - warning( - typeof index !== 'undefined' && ret && !getSourceHasBeenCalled, - `You're using a FormDataConsumer inside an ArrayInput and you did not call the getSource function supplied by the FormDataConsumer component. This is required for your inputs to get the proper source. - - - - - - - {({ - formData, // The whole form data - scopedFormData, // The data for this item of the ArrayInput - getSource, // A function to get the valid source inside an ArrayInput - ...rest, - }) => - scopedFormData.name ? ( - - ) : null - } - - -` - ); - return ret === undefined ? null : ret; }; From 54d10f083abeb1fbea3eabc72e31d43e8bfe4e7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?An=C3=ADbal=20Svarcas?= Date: Tue, 29 Nov 2022 10:35:59 -0300 Subject: [PATCH 2/3] Fix documentation --- docs/SimpleFormIterator.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/SimpleFormIterator.md b/docs/SimpleFormIterator.md index cb712af6f0f..fedcb8c2446 100644 --- a/docs/SimpleFormIterator.md +++ b/docs/SimpleFormIterator.md @@ -147,7 +147,7 @@ const PostEdit = () => ( ); ``` -**Note**: `` only accepts `Input` components as children. If you want to use some `Fields` instead, you have to use a `` to get the correct source, as follows: +**Note**: `` only accepts `Input` components as children. If you want to use some `Fields` instead, you have to use a ``, as follows: ```jsx import { ArrayInput, SimpleFormIterator, DateInput, TextField, FormDataConsumer, Labeled } from 'react-admin'; @@ -156,9 +156,9 @@ import { ArrayInput, SimpleFormIterator, DateInput, TextField, FormDataConsumer, - {({ getSource }) => ( + {({ scopedFormData }) => ( - + )} From c393e92d76fd27cfb3efd9a20675a43d636ff94a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?An=C3=ADbal=20Svarcas?= Date: Tue, 29 Nov 2022 10:50:28 -0300 Subject: [PATCH 3/3] Fix warning --- packages/ra-core/src/form/FormDataConsumer.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/ra-core/src/form/FormDataConsumer.tsx b/packages/ra-core/src/form/FormDataConsumer.tsx index 8e1307bbf8f..76f78a2cf10 100644 --- a/packages/ra-core/src/form/FormDataConsumer.tsx +++ b/packages/ra-core/src/form/FormDataConsumer.tsx @@ -3,7 +3,6 @@ import { ReactNode } from 'react'; import { useWatch, useFormContext, FieldValues } from 'react-hook-form'; import get from 'lodash/get'; -import warning from '../util/warning'; /** * Get the current (edited) value of the record from the form and pass it * to a child function