-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
submitting edit form creates fields with empty string ("") value in a record instead of keeping them uninitialized #7972
Comments
Related to #7782? |
a bit similar but not. In my case API simply doesn't have some values. But they are assigned to "" when data is sent back on submit |
Hi @SerhiyAndryeyev |
I'm seeing the same, we have a NumberInput in an ArrayInput and it's now submitting an empty string instead of nothing in v4 compared to v3, which of course breaks our graphql backend. Using If Serhiy doesn't come through with a codesandbox, I'll see if I can come up with one. |
https://codesandbox.io/s/react-admin-demo-issue-0hted9?file=/src/comments/CommentEdit.tsx |
Same as #8060 ? |
yes, the same |
Hi guys, So indeed, this is actually a breaking change from v3 to v4, due to the change of the forms library.
This is what is implemented in react-admin. If you need to workaround this, you can use the Since we do not plan to change this, I'm going to close this issue. |
Probably there was misunderstanding of the prolem. We for instance work with mongodb which doesnt have fixed data scheme. Some values (randomly) are simply not fetched to the form. So I expected react admin to handle correctly the case when those fields stay untouched on save. So they should not be written back to DB. Unfortunatelly because the way react-hook-form was integrated it became impossible in v4.
I hope to see it reflected in some future version of ra |
@pablos44 I think you're complaining to the wrong guy. You're right that the behavior of our forms about default values have changed between v3 and v4. In v3, react-final-form automatically sanitized empty inputs, and it created problems for some users. in v4, react-hook-form doesn't sanitize empty inputs, and it's also not the expected behavior for all. What I mean is that there is not one-size-fits-all solution for this problem. We try to avoid adding custom logic on top of the frameworks we use, and we embrace their philosophy as much as possible. So if react-hook-form doesn't sanitize empty values by default, so does react-admin. If you think this is a flaw, it's probably a flaw in the underlying form framework, and it should be fixed there, not here. So I invite you to open an issue on the react-hook-form repository about your problem.
If there is a way to pass the form state (and not only the form data) to Also, you can use a form resolver to transform the data before it's submitted based on a context object that you manipulate. We're doing our best to communicate about this gotcha (cf #8156), but I'm afraid it can't be fixed in react-admin. |
What you were expecting:
I have SimpleForm form with a but subtitle does not exist in fetched data. When a user saves the form without changing the "subtitle" I expect this field to be empty or undefined because the user did not modify it.
What happened instead:
When the form is submitted the data field "subtitle" gets an empty string ("") value. This breaks the integrity of our data because its field is not supposed to be assigned in this way. In the previous version (v3) of react-admin the field was not created if it is not explicitly filled by a user
Steps to reproduce:
original data loaded to form:
The data after submit(pay attention to "subtitle" field added:
Related code:
the code of the form below. This is actually from react-admin tutorial
Other information:
Using parse method to convert empty strings to undefined does not help because empty string value ("") is also a valid value for some fields.
I tried to implement detection of dirty fields using a combination of useFormState and transform callback but it seems strange that this functionality is not supported out of the box
The text was updated successfully, but these errors were encountered: