Skip to content

Commit a3d0d82

Browse files
author
Krzysztof Marek Witkowski
committed
fix(simple form iterator): defaulted values to null instead of empty string
1 parent 5e61836 commit a3d0d82

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

packages/ra-core/src/form/FormDataConsumer.spec.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import * as React from 'react';
2-
import { render, waitFor, screen, fireEvent } from '@testing-library/react';
2+
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
33

44
import FormDataConsumer, { FormDataConsumerView } from './FormDataConsumer';
55
import { testDataProvider } from '../dataProvider';
66
import {
77
AdminContext,
8+
ArrayInput,
89
BooleanInput,
910
SimpleForm,
10-
TextInput,
1111
SimpleFormIterator,
12-
ArrayInput,
12+
TextInput,
1313
} from 'ra-ui-materialui';
1414
import expect from 'expect';
1515

@@ -146,7 +146,7 @@ describe('FormDataConsumerView', () => {
146146

147147
fireEvent.click(screen.getByLabelText('ra.action.add'));
148148

149-
expect(globalScopedFormData).toEqual({ name: '' });
149+
expect(globalScopedFormData).toEqual({ name: null });
150150

151151
fireEvent.change(
152152
screen.getByLabelText('resources.undefined.fields.authors.name'),

packages/ra-ui-materialui/src/input/ArrayInput/SimpleFormIterator.spec.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import * as React from 'react';
22
import {
3-
screen,
4-
render,
53
fireEvent,
6-
waitFor,
74
getByLabelText,
5+
render,
6+
screen,
7+
waitFor,
88
} from '@testing-library/react';
99
import expect from 'expect';
1010
import { FormDataConsumer, testDataProvider } from 'ra-core';
@@ -770,7 +770,7 @@ describe('<SimpleFormIterator />', () => {
770770
await waitFor(() => {
771771
expect(save).toHaveBeenCalledWith(
772772
{
773-
emails: [{ email: '' }],
773+
emails: [{ email: null }],
774774
},
775775
expect.anything()
776776
);
@@ -853,7 +853,7 @@ describe('<SimpleFormIterator />', () => {
853853
expect(save).toHaveBeenCalledWith(
854854
{
855855
id: 1,
856-
emails: [{ email: '', role: '' }],
856+
emails: [{ email: null, role: null }],
857857
},
858858
expect.anything()
859859
);

packages/ra-ui-materialui/src/input/ArrayInput/SimpleFormIterator.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export const SimpleFormIterator = (props: SimpleFormIteratorProps) => {
7575
const { id, ...rest } = fields[0];
7676
initialDefaultValue.current = rest;
7777
for (const k in initialDefaultValue.current)
78-
initialDefaultValue.current[k] = '';
78+
initialDefaultValue.current[k] = null;
7979
}
8080

8181
const addField = useCallback(
@@ -104,7 +104,7 @@ export const SimpleFormIterator = (props: SimpleFormIteratorProps) => {
104104
input.props.source
105105
) {
106106
defaultValue[input.props.source] =
107-
input.props.defaultValue ?? '';
107+
input.props.defaultValue ?? null;
108108
}
109109
});
110110
}

0 commit comments

Comments
 (0)