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] Add Forms dedicated chapter #9864

Merged
merged 5 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion docs/AccordionForm.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export const PostCreate = () => (

**Tip**: You can include properties in the form `defaultValues` that are not listed as input components, like the `created_at` property in the previous example.

**Tip**: React-admin also allows to define default values at the input level. See the [Setting default Values](./EditTutorial.md#setting-default-values) section.
**Tip**: React-admin also allows to define default values at the input level. See the [Setting default Values](./Forms.md#default-values) section.

## `id`

Expand Down
481 changes: 9 additions & 472 deletions docs/EditTutorial.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/Features.md
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ These building blocks include:
And if you want to create your building blocks, you can use any of the [75+ hooks](./Reference.md#hooks) that carry **headless, reusable logic**. To name a few of them:

- [`useRecordContext`](./useRecordContext.md) to get the current record anywhere in the app
- [`useWarnWhenUnsavedChanges`](./EditTutorial.md#warning-about-unsaved-changes) to warn the user when he tries to leave a page with unsaved changes
- [`useWarnWhenUnsavedChanges`](./Forms.md#warning-about-unsaved-changes) to warn the user when he tries to leave a page with unsaved changes
- [`useSaveContext`](./useSaveContext.md) to tweak form submission
- [`useTheme`](./useTheme.md) to change the theme programmatically

Expand Down
2 changes: 1 addition & 1 deletion docs/Form.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const PostCreate = () => (

**Tip**: You can include properties in the form `defaultValues` that are not listed as input components, like the `created_at` property in the previous example.

**Tip**: React-admin also allows to define default values at the input level. See the [Setting default Values](./EditTutorial.md#setting-default-values) section.
**Tip**: React-admin also allows to define default values at the input level. See the [Setting default Values](./Forms.md#default-values) section.

## `id`

Expand Down
768 changes: 768 additions & 0 deletions docs/Forms.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/Inputs.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ If `true`, the input is disabled and the user can't change the value.
<TextInput source="title" disabled />
```

**Tip**: The form framework used by react-admin, react-hook-form, [considers](https://github.com/react-hook-form/react-hook-form/pull/10805) that a `disabled` input shouldn't submit any value. So react-hook-form sets the value of all `disabled` inputs to `undefined`. As a consequence, a form with a `disabled` input is always considered `dirty` (i.e. react-hook-form considers that the form values and the initial record values are different), and it triggers [the `warnWhenUnsavedChanges` feature](./EditTutorial.md#warning-about-unsaved-changes) when leaving the form, even though the user changed nothing. The workaround is to set the `disabled` prop on the underlying input component, as follows:
**Tip**: The form framework used by react-admin, react-hook-form, [considers](https://github.com/react-hook-form/react-hook-form/pull/10805) that a `disabled` input shouldn't submit any value. So react-hook-form sets the value of all `disabled` inputs to `undefined`. As a consequence, a form with a `disabled` input is always considered `dirty` (i.e. react-hook-form considers that the form values and the initial record values are different), and it triggers [the `warnWhenUnsavedChanges` feature](./Forms.md#warning-about-unsaved-changes) when leaving the form, even though the user changed nothing. The workaround is to set the `disabled` prop on the underlying input component, as follows:

{% raw %}
```jsx
Expand Down
2 changes: 1 addition & 1 deletion docs/LongForm.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export const PostCreate = () => (

**Tip**: You can include properties in the form `defaultValues` that are not listed as input components, like the `created_at` property in the previous example.

**Tip**: React-admin also allows to define default values at the input level. See the [Setting default Values](./EditTutorial.md#setting-default-values) section.
**Tip**: React-admin also allows to define default values at the input level. See the [Setting default Values](./Forms.md#default-values) section.

## `id`

Expand Down
2 changes: 1 addition & 1 deletion docs/Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ title: "Index"
* [`useUpdateMany`](./useUpdateMany.md)

**- W -**
* [`useWarnWhenUnsavedChanges`](./EditTutorial.md#warning-about-unsaved-changes)
* [`useWarnWhenUnsavedChanges`](./Forms.md#warning-about-unsaved-changes)
* [`withLifecycleCallbacks`](./withLifecycleCallbacks.md)

</div>
2 changes: 1 addition & 1 deletion docs/SimpleForm.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export const PostCreate = () => (

**Tip**: You can include properties in the form `defaultValues` that are not listed as input components, like the `created_at` property in the previous example.

**Tip**: React-admin also allows to define default values at the input level. See the [Setting default Values](./EditTutorial.md#setting-default-values) section.
**Tip**: React-admin also allows to define default values at the input level. See the [Setting default Values](./Forms.md#default-values) section.

## `id`

Expand Down
2 changes: 1 addition & 1 deletion docs/TabbedForm.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export const PostCreate = () => (

**Tip**: You can include properties in the form `defaultValues` that are not listed as input components, like the `created_at` property in the previous example.

**Tip**: React-admin also allows to define default values at the input level. See the [Setting default Values](./EditTutorial.md#setting-default-values) section.
**Tip**: React-admin also allows to define default values at the input level. See the [Setting default Values](./forms.md#default-values) section.

## `id`

Expand Down
2 changes: 1 addition & 1 deletion docs/WizardForm.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const PostCreate = () => (

**Tip**: You can include properties in the form `defaultValues` that are not listed as input components, like the `created_at` property in the previous example.

**Tip**: React-admin also allows to define default values at the input level. See the [Setting default Values](./EditTutorial.md#setting-default-values) section.
**Tip**: React-admin also allows to define default values at the input level. See the [Setting default Values](./forms.md#default-values) section.

## `id`

Expand Down
4 changes: 4 additions & 0 deletions docs/css/style-v20.css
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ ul.sidenav code {
background: 0 0;
}

.markdown-section a code {
color: #4183c4;
}

.markdown-section a:active,
.markdown-section a:focus,
.markdown-section a:hover {
Expand Down
Binary file added docs/img/Forms.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/form-layouts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@

<ul><div>Creation & Edition Pages</div>
<li {% if page.path == 'EditTutorial.md' %} class="active beginner" {% else %} class="beginner" {% endif %}><a class="nav-link" href="./EditTutorial.html">Introduction</a></li>
<li {% if page.path == 'Forms.md' %} class="active beginner" {% else %} class="beginner" {% endif %}><a class="nav-link" href="./Forms.html">Forms</a></li>
<li {% if page.path == 'Validation.md' %} class="active beginner" {% else %} class="beginner" {% endif %}><a class="nav-link" href="./Validation.html">Form Validation</a></li>
<li {% if page.path == 'Create.md' %} class="active beginner" {% else %} class="beginner" {% endif %}><a class="nav-link" href="./Create.html"><code>&lt;Create&gt;</code></a></li>
<li {% if page.path == 'CreateBase.md' %} class="active" {% endif %}><a class="nav-link" href="./CreateBase.html"><code>&lt;CreateBase&gt;</code></a></li>
Expand Down
Loading