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

Bug: DateInput & ArrayInput - formatOnBlur triggers undefined ref in react-final-form #6459

Closed
SchaeVHS opened this issue Jul 22, 2021 · 7 comments
Labels

Comments

@SchaeVHS
Copy link

SchaeVHS commented Jul 22, 2021

Dear Team,
many thanks for react-admin and your work!

Version
"react": "^16.7.0",
"react-admin": "^3.17.0",
"react-scripts": "4.0.3",

Code Basis of bug

<ArrayInput source="positions" >
                    <SimpleIterator > 
                        <DateInput source="delivery_date"/>
                        <DateInput source="payment_date"/>
                    </SimpleIterator>
  </ArrayInput>

Problem
If you have multiple array elements and delete an array element in the middle by clicking on the delete button,
the EDIT form is not submitted/saved when clicking on the EDIT save button.

Observation
The browser console reports
grafik

Looking at the code it is that following react-final-form code which is triggered:
https://github.com/final-form/react-final-form/blob/2d9e7129f40efd39450c1d581956e8cfce17a20a/src/useField.js#L68

This only happens in react-admin for datefields, as datefields set "formatOnBlur":

Summary
I think it is a mixed problem:

  1. React final form doesn't check the return value of getFielState()
  2. react-admin SimpleFormIterator somehow deletes the fields in a way, that react-final-form still wants to iterate over it,
    although they are deleted?

I would really appreciate a fix, I have no idea how to proceed. With your help I can also offer to fix it myself,
but I'm lost. Is it react-final-form or is it react-admin which causes this?

Regards,
Daniel

@djhi
Copy link
Collaborator

djhi commented Jul 22, 2021

Thanks for reporting this. As I can't reproduce this issue on our simple example (see the posts edit which has an ArrayInput with DateInputs), please provide a sample application showing the issue by forking the following CodeSandbox (https://codesandbox.io/s/github/marmelab/react-admin/tree/master/examples/simple).

@SchaeVHS
Copy link
Author

SchaeVHS commented Jul 22, 2021

Many Many thanks for your template! This helped me alot!

https://codesandbox.io/s/infallible-goldberg-4pgb7?file=/src/posts/PostEdit.tsx

Steps to reproduce

  • Go to posts
  • Select the only post
  • Delete the middle backlink
    grafik
  • Hit Save

--> Nothing happens

EDIT:
maybe related:
final-form/react-final-form-arrays#165

EDIT 2:
If I set the following line to false, my problem vanishes.
I don't know exactly what other implications I may add with this change.

@SchaeVHS
Copy link
Author

Do you need more information or can I help somehow? I'm still not sure, that formatOnBlur: false, is the right solution?

@SchaeVHS
Copy link
Author

SchaeVHS commented Sep 8, 2021

What information do you need? Please tell me.

I have the above change of formatOnBlur: false working since July and I haven't got negative feedback so far.

@djhi
Copy link
Collaborator

djhi commented Sep 8, 2021

Thanks for the sandbox. We need to investigate and see if we can do something about it. In the mean time, your workaround looks correct.

@WiXSL
Copy link
Contributor

WiXSL commented Nov 17, 2021

@djhi, could this be closed?

@djhi
Copy link
Collaborator

djhi commented Nov 18, 2021

Indeed, it should be

@djhi djhi closed this as completed Nov 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants