Skip to content
New issue

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

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

Already on GitHub? # to your account

Prefilling create form by using location's state or search does not work #7672

Closed
dannyan2014 opened this issue May 9, 2022 · 1 comment · Fixed by #7684
Closed

Prefilling create form by using location's state or search does not work #7672

dannyan2014 opened this issue May 9, 2022 · 1 comment · Fixed by #7684
Assignees

Comments

@dannyan2014
Copy link

What you were expecting:

According to Prefilling the Form document, create form should be filled with the values provided.

What happened instead:

Location's state is null and inputs are blank.

Steps to reproduce:

Use a customized create button with state or search.

<Button
    component={Link}
    to={{
      pathname: "/posts/create",
      state: {
        record: {
          title: "foobar"
        }
      },
      search: "?teaser=teaser"
    }}
    color="primary"
    size="small"
>

Related code:

https://codesandbox.io/s/ancient-worker-jlmxgn?file=/src/posts/PostActions.js

Environment

  • React-admin version: 4.0.2
  • Last version that did not exhibit the issue (if applicable): 3.19
  • React version:
  • Browser:
  • Stack trace (in case of a JS error):
@slax57
Copy link
Contributor

slax57 commented May 11, 2022

Hi,
Thank you for submitting this.
Actually this is a mistake in the documentation, here is how to achieve this:

    <Button
      component={Link}
      to={{
        pathname: "/posts/create",
-       state: {
-         record: {
-           title: "foobar"
-         }
-       },
        search: "?teaser=teaser"
      }}
+     state={{
+       record: {
+         title: "foobar"
+       }
+     }}
      color="primary"
      size="small"
    >
      Create Prefill
    </Button>

I'll mark this as a documentation issue.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants