Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Doc] Mention CreateInDialog in ReferenceManyField doc #10054

Merged
merged 3 commits into from
Jul 26, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions docs/ReferenceManyField.md
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want an other section with an example of <EditInDialogButton> too ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes: you could add the button to the datagrid

Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,45 @@ In these cases, use [the `<ReferenceOneField>` component](./ReferenceOneField.md
</ReferenceOneField>
```
{% endraw %}

## Adding a related record

To allow users to create a record without leaving the current view, use the [`<CreateInDialogButton>`](./CreateInDialogButton.md) component.

{% raw %}
```jsx
import { Edit, SimpleForm, TextInput, ReferenceManyField, WithRecord, Datagrid } from 'react-admin';
import { CreateInDialogButton } from "@react-admin/ra-form-layout";

const EmployerEdit = () => (
<Edit>
<SimpleForm>
<TextInput source="name" />
<TextInput source="address" />
<TextInput source="city" />
<ReferenceManyField
target="employer_id"
reference="customers"
>
<WithRecord
render={record => (
<CreateInDialogButton
record={{ employer_id: record.id }}
>
<SimpleForm>
<TextInput source="first_name" />
<TextInput source="last_name" />
</SimpleForm>
</CreateInDialogButton>
)}
/>
<Datagrid>
<TextField source="first_name" />
<TextField source="last_name" />
</Datagrid>
</ReferenceManyField>
</SimpleForm>
</Edit>
)
```
{% endraw %}
Loading