React-admin: [3.11] SaveButton inside FormWithRedirect component throws error

Created on 18 Dec 2020  路  10Comments  路  Source: marmelab/react-admin

The custom form shown here:
https://marmelab.com/react-admin/CreateEdit.html#custom-form-component
No longer works with react-admin v3.11

I copy-paste the above sample as the Post form in the following sandbox:
https://codesandbox.io/s/charming-mahavira-kuphi?file=/src/posts/PostCreate.js

  1. Create a new Post
  2. You get the error TypeError: Cannot read property 'save' of undefined

Environment

  • React-admin version: 3.11
  • Last version that did not exhibit the issue (if applicable): 3.10.4
  • React version: 17.0.1
  • Browser: Google Chrome latest
bug

Most helpful comment

5738 has just been merged, which solves the problem (At least the one I reported) at least until the next mayor release. By then it would be my responsibility to upgrade my code to use SaveContext of course.

All 10 comments

@WiXSL follow documentation properly,enclose FormWithRedirect Component within Create tags and replace resource and source props in Input fields with correct value

My example wasn't the best. But I have code like that, that was working before verion 3.11.
I'll re-do the example.
Basically I have a mui Dialog with a FormWithRedirect inside that is opened from a List bulkActionButtons's button.

Using FormWithRedirect outside of Create or Edit isn't something we encourage. Use react-final-form's <Form> component for such cases.

Same here, three views on my side were broken after 3.11 update. Changing from the react-admin SimpleForm to the Form component from react-final-form and reimplementing handleSubmit fixed them. But this is a dangerous breaking change introduced for many users here. They are some SO post talking about it.

I'm sorry that you were bitten by this as well, but it's not a breaking change if the feature was never documented.

@fzaninotto , the DEMO examples are not updated to this latest changes

@alextaymx Not sure what you're talking about. Can you be more specific?

5738 has just been merged, which solves the problem (At least the one I reported) at least until the next mayor release. By then it would be my responsibility to upgrade my code to use SaveContext of course.

@fzaninotto , if i'm not mistaken, in the demo repo, the Review Edit part https://github.com/marmelab/react-admin/blob/master/examples/demo/src/reviews/ReviewEdit.tsx is using SimpleForm without Edit component, this is where the error pops out.

@alextaymx You're right. Since @WiXSL's patch, it only logs a warning, but it should be changed. I'll update the demo.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

9747749366 picture 9747749366  路  3Comments

ilaif picture ilaif  路  3Comments

Dragomir-Ivanov picture Dragomir-Ivanov  路  3Comments

fzaninotto picture fzaninotto  路  3Comments

kdabir picture kdabir  路  3Comments