From 0a4c6427d2d4f966c022933cdbc144638cac284c Mon Sep 17 00:00:00 2001
From: Gildas Garcia <1122076+djhi@users.noreply.github.com>
Date: Fri, 5 Feb 2021 16:43:02 +0100
Subject: [PATCH] Fix ArrayInput Always Override Inputs disabled Prop
---
.../src/form/SimpleFormIterator.spec.tsx | 31 +++++++++++++++++++
.../src/form/SimpleFormIterator.tsx | 25 ++++++++++-----
2 files changed, 48 insertions(+), 8 deletions(-)
diff --git a/packages/ra-ui-materialui/src/form/SimpleFormIterator.spec.tsx b/packages/ra-ui-materialui/src/form/SimpleFormIterator.spec.tsx
index 3caaf003b12..070bb50d8dc 100644
--- a/packages/ra-ui-materialui/src/form/SimpleFormIterator.spec.tsx
+++ b/packages/ra-ui-materialui/src/form/SimpleFormIterator.spec.tsx
@@ -94,6 +94,37 @@ describe('', () => {
expect((inputElements[1] as HTMLInputElement).value).toBe('bar');
});
+ it('should allow to override the disabled prop of each inputs', () => {
+ const { queryAllByLabelText } = renderWithRedux(
+
+
+
+
+
+
+
+
+
+
+
+
+
+ );
+ const inputElements = queryAllByLabelText(
+ 'resources.undefined.fields.email'
+ );
+ expect(inputElements).toHaveLength(2);
+ expect((inputElements[0] as HTMLInputElement).disabled).toBeTruthy();
+ expect((inputElements[0] as HTMLInputElement).value).toBe('foo');
+ expect((inputElements[1] as HTMLInputElement).disabled).toBeTruthy();
+ expect((inputElements[1] as HTMLInputElement).value).toBe('bar');
+ });
+
it('should display an add item button at least', () => {
const { getByText } = renderWithRedux(
diff --git a/packages/ra-ui-materialui/src/form/SimpleFormIterator.tsx b/packages/ra-ui-materialui/src/form/SimpleFormIterator.tsx
index 0fb1f314a81..d9406df9e60 100644
--- a/packages/ra-ui-materialui/src/form/SimpleFormIterator.tsx
+++ b/packages/ra-ui-materialui/src/form/SimpleFormIterator.tsx
@@ -201,29 +201,37 @@ const SimpleFormIterator: FC = props => {
{Children.map(
children,
- (input: ReactElement, index2) =>
- isValidElement(input) ? (
+ (input: ReactElement, index2) => {
+ if (!isValidElement(input)) {
+ return null;
+ }
+ const {
+ source,
+ ...inputProps
+ } = input.props;
+ return (
= props => {
variant={variant}
margin={margin}
/>
- ) : null
+ );
+ }
)}
{!disabled &&