Skip to content

Commit ed3c81d

Browse files
committed
revert the fix (and story)
1 parent 2c8de73 commit ed3c81d

File tree

2 files changed

+10
-126
lines changed

2 files changed

+10
-126
lines changed

packages/ra-core/src/form/useAugmentedForm.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,7 @@ export const useAugmentedForm = <RecordType = any>(
7070

7171
const form = useForm({
7272
criteriaMode,
73-
// We need to provide both `values` and `defaultValues`, because
74-
// - we need `values` to be able to reactively reset the form when the record changes
75-
// - we need `defaultValues` because `useController` requires them to function properly
76-
// (omitting them can cause issues with reset or with shouldUnregister)
77-
// See https://react-hook-form.com/docs/usecontroller#props
7873
values: defaultValuesIncludingRecord,
79-
defaultValues: defaultValuesIncludingRecord,
8074
reValidateMode,
8175
resolver: finalResolver,
8276
...rest,

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

Lines changed: 10 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
1-
import * as React from 'react';
2-
import { Admin } from 'react-admin';
1+
import { InputAdornment } from '@mui/material';
32
import {
4-
FormDataConsumer,
53
required,
64
Resource,
75
testI18nProvider,
86
TestMemoryRouter,
97
} from 'ra-core';
10-
import { InputAdornment } from '@mui/material';
11-
import fakeRestProvider from 'ra-data-fakerest';
8+
import * as React from 'react';
9+
import { Admin } from 'react-admin';
1210

13-
import { Edit, Create } from '../../detail';
11+
import { Create, Edit } from '../../detail';
12+
import { ReferenceField, TextField, TranslatableFields } from '../../field';
1413
import { SimpleForm, TabbedForm } from '../../form';
15-
import { ArrayInput } from './ArrayInput';
16-
import { SimpleFormIterator } from './SimpleFormIterator';
17-
import { TextInput } from '../TextInput';
18-
import { SelectInput } from '../SelectInput';
14+
import { Labeled } from '../../Labeled';
15+
import { AutocompleteInput } from '../AutocompleteInput';
1916
import { DateInput } from '../DateInput';
2017
import { NumberInput } from '../NumberInput';
21-
import { AutocompleteInput } from '../AutocompleteInput';
18+
import { TextInput } from '../TextInput';
2219
import { TranslatableInputs } from '../TranslatableInputs';
23-
import { ReferenceField, TextField, TranslatableFields } from '../../field';
24-
import { Labeled } from '../../Labeled';
25-
import { List, Datagrid } from '../../list';
20+
import { ArrayInput } from './ArrayInput';
21+
import { SimpleFormIterator } from './SimpleFormIterator';
2622

2723
export default { title: 'ra-ui-materialui/input/ArrayInput' };
2824

@@ -828,109 +824,3 @@ export const WithReferenceField = () => (
828824
</Admin>
829825
</TestMemoryRouter>
830826
);
831-
832-
const shouldUnregisterData = {
833-
books: [
834-
{
835-
id: 1,
836-
title: 'War and Peace',
837-
authors: [
838-
{
839-
name: 'Alexander Pushkin',
840-
role: 'co_writer',
841-
},
842-
{
843-
// name: 'Leo Tolstoy',
844-
role: 'head_writer',
845-
},
846-
],
847-
},
848-
{
849-
id: 2,
850-
title: 'Anna Karenina',
851-
authors: [
852-
{
853-
// name: 'Leo Tolstoy',
854-
role: 'head_writer',
855-
},
856-
{
857-
name: 'Alexander Pushkin',
858-
role: 'co_writer',
859-
},
860-
],
861-
},
862-
],
863-
};
864-
865-
const WithShouldUnregisterBookList = () => {
866-
return (
867-
<List>
868-
<Datagrid>
869-
<TextField source="id" />
870-
<TextField source="title" />
871-
</Datagrid>
872-
</List>
873-
);
874-
};
875-
const WithShouldUnregisterBookEdit = () => {
876-
return (
877-
<Edit
878-
mutationMode="pessimistic"
879-
mutationOptions={{
880-
onSuccess: data => {
881-
console.log(data);
882-
},
883-
}}
884-
>
885-
<SimpleForm>
886-
<TextInput source="title" />
887-
<ArrayInput source="authors">
888-
<SimpleFormIterator>
889-
<FormDataConsumer>
890-
{({ scopedFormData }) => {
891-
return (
892-
<>
893-
<SelectInput
894-
source="role"
895-
choices={[
896-
'co_writer',
897-
'head_writer',
898-
]}
899-
/>
900-
{scopedFormData?.role ===
901-
'co_writer' ? (
902-
<TextInput
903-
source="name"
904-
shouldUnregister
905-
/>
906-
) : null}
907-
</>
908-
);
909-
}}
910-
</FormDataConsumer>
911-
</SimpleFormIterator>
912-
</ArrayInput>
913-
</SimpleForm>
914-
</Edit>
915-
);
916-
};
917-
918-
export const WithShouldUnregister = () => (
919-
<React.StrictMode>
920-
<TestMemoryRouter initialEntries={['/books/1']}>
921-
<Admin
922-
dataProvider={fakeRestProvider(
923-
JSON.parse(JSON.stringify(shouldUnregisterData)),
924-
true,
925-
300
926-
)}
927-
>
928-
<Resource
929-
name="books"
930-
list={WithShouldUnregisterBookList}
931-
edit={WithShouldUnregisterBookEdit}
932-
/>
933-
</Admin>
934-
</TestMemoryRouter>
935-
</React.StrictMode>
936-
);

0 commit comments

Comments
 (0)