react-admin icon indicating copy to clipboard operation
react-admin copied to clipboard

Can not display Fields in Create or Edit View

Open LanaIV opened this issue 7 years ago • 9 comments

What you were expecting: Display Fields in Create and Edit Views.

What happened instead: The empty div is displayed for Fields.

Steps to reproduce: Add TextField with valide source in Edit or Create View.

In the documentation it is mentioned that it could be possible: https://github.com/marmelab/react-admin/blob/925408c86b665fa026c7798b4af10fc70127be86/docs/Fields.md

Environment

  • React-admin version: 2.7.1
  • Last version that did not exhibit the issue (if applicable):
  • React version: 16.8.1
  • Browser: Chrome
  • Stack trace (in case of a JS error):

LanaIV avatar Mar 26 '19 22:03 LanaIV

If you are able to illustrate the bug or feature request with an example, please provide a sample application via one of the following means:

  • CodeSandbox (https://codesandbox.io/s/349ovjmlx5)
  • A sample application via GitHub

djhi avatar Mar 27 '19 05:03 djhi

@djhi @LanaIV Looks like I found a way to reproduce it stabile: https://codesandbox.io/s/q7vvq29n3w

Consider PostsEdit view - when we put Input and Fields component (title in example) into div (or any other parent component), only Inputs are rendered.

In my case I faced with it when using MUI's Grid to customize layout.

tusmenko avatar Mar 27 '19 09:03 tusmenko

@tusmenko I don't get it. The field is rendered in your codesandbox.

image

djhi avatar Mar 27 '19 10:03 djhi

Oh sorry misread. @tusmenko this is another issue than the one described by @LanaIV. Indeed, the way react-admin works does not allow wrapping containers. You'll have to implement your own SimpleForm or TabbedForm for that.

djhi avatar Mar 27 '19 10:03 djhi

@LanaIV What @tusmenko codesandbox shows however, is that you can include fields in a Edit view.

djhi avatar Mar 27 '19 10:03 djhi

@djhi Generally It's allow, but, as you see - only Inputs, but not Edits( Is it feature request in this case, or new bug-request to create?

tusmenko avatar Mar 27 '19 10:03 tusmenko

Generally It's allow, but, as you see - only Inputs, but not Edits

It looks like it works but it shouldn't and is not supported. The SimpleForm and FormTab components currently inspect their children and clone them with additional props. Wrapping your inputs with any components which does not pass them those additional props down will most probably trigger bugs.

This is a known issue that we won't address any time soon. You'll have to implement your own Form component or wrappers for that. If you wish to discuss it more, please open a new issue

djhi avatar Mar 27 '19 10:03 djhi

Sorry for delay with my response. When I was trying with sandbox rendering of TextField & ImageField (the most important for me) was displayed, so I tried to figure out why in my code it did not work. My fields and inputs are wrapped with other containers, so it should be because of that. When I put the fields out of containers it works.

This is a known issue that we won't address any time soon. You'll have to implement your own Form component or wrappers for that.

I'll try to implement my own component. Thanks!

LanaIV avatar Mar 29 '19 00:03 LanaIV

There should be documentation for how to render a Field component inside of a Create/Edit component for custom layouts.

calebfaruki avatar Nov 04 '20 12:11 calebfaruki