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

DateInput or ArrayInput with warnWhenUnsavedChanges are triggering an alert when submitting the form #5267

Closed
otroboe opened this issue Sep 17, 2020 · 14 comments
Labels

Comments

@otroboe
Copy link

otroboe commented Sep 17, 2020

Hello!

What you were expecting:
I'm using the warnWhenUnsavedChanges option on my TabbedForm, it was working as expected until I add a DateInput in my form.
When I update my date in the form, I don't want to have the "unsaved" alert when I'm submitting my changes.

What happened instead:

  • When I change the date in my form, I have the "unsaved" alert when I submit the form.
  • When I change other fields (and not the date), I don't have the issue.
  • When I confirm the alert, the submit is working, my date is correctly saved.
  • It seems to be the same issue with DateTimeInput.

Steps to reproduce:
Using the option warnWhenUnsavedChanges in a TabbedForm, with a DateInput inside it.

Related code:
I don't have much code to show, the components are a bit split:

export const UnitCreate: FC = (props: any) => (
  <Create {...props} undoable={0}>
    <TabbedForm warnWhenUnsavedChanges>
      <MainFormTab />
      <TermsFormTab />
    </TabbedForm>
  </Create>
);
export const MainFormTab: FC<MainFormTabProps> = (props: any) => {
  return (
    <GenericMainFormTab {...props} hideDefaultField>
      <TextInput
        disabled={props.disabled}
        fullWidth
        label="resources.unit.title"
        source="title"
        validate={[required()]}
      />
      <DateInput
        disabled={props.disabled}
        label="resources.unit.rightsEndDate"
        source="rightsEndDate"
      />
    </GenericMainFormTab>
  );
};

ezgif-3-3152748be90c

Environment

  • React-admin version: 3.8.4
  • React version: 16.13.1
  • Browser: Chrome 85
@djhi
Copy link
Collaborator

djhi commented Sep 18, 2020

Thanks for reporting this. Can you 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)?

@otroboe
Copy link
Author

otroboe commented Sep 18, 2020

@djhi I tried to reproduce the bug on the sandbox with the <TagEdit /> component, but with no "luck".
I tried to reproduce the structure of my app, with TabbedForm / FormTab and stuff, but it keeps working 😄

So there must be something else I'm doing to trigger this error, I'll keep investigate on my side inside my project. But If I don't find anything, I'll close this issue!

Thank you!

@otroboe
Copy link
Author

otroboe commented Sep 18, 2020

@djhi I found how to reproduce it! In my project, I have to remove all of the "Array Inputs" to make it work:

<ReferenceArrayInput>
  <AutocompleteArrayInput />
</ReferenceArrayInput>

and

<ArrayInput>
  <SimpleFormIterator />
</ArrayInput>

So I tried to find one of these cases in the sandbox, and I didn't find the exact same setup, but the same bug, with the example (without doing a fork).

You have to pick a Post with already some backLinks, for example the Omnis voluptate one, and change only the date of the backlink, and press "Save", you should see the "unsaved warning".

When updating only the pushishedAt date, we don't have the issue, that's the use case in my project which is failing. But I'm pretty sure both are related, because triggered by "Array Inputs".

I'm joining the "video" of the bug in the example, tell me if you need more informations!
Thank you!

ezgif-3-4cef1d593d4c

@djhi
Copy link
Collaborator

djhi commented Sep 18, 2020

A link to the codesandbox would help

@otroboe
Copy link
Author

otroboe commented Sep 18, 2020

I didn't need to fork it, the bug in the gif from my previous message, is coming from the example:
https://codesandbox.io/s/github/marmelab/react-admin/tree/master/examples/simple

@otroboe
Copy link
Author

otroboe commented Sep 18, 2020

I found out that the issue is not only for the DateInput. If you modify the url of a backlink in the example, it will trigger the alert too.

Edit: In my project, when I modify my ReferenceArrayInput / AutocompleteArrayInput, it's triggering the alert also :(

@otroboe
Copy link
Author

otroboe commented Sep 22, 2020

What more infos do I need to give? I can rename and edit the issue, but I simply describe an issue with the example afterall.

@djhi
Copy link
Collaborator

djhi commented Sep 22, 2020

Should be enough, thanks. We now need time to investigate

@MLukman
Copy link

MLukman commented Nov 14, 2020

I too have the same issue with ArrayInput.

@otroboe
Copy link
Author

otroboe commented Dec 4, 2020

@MLukman Yes, it's not only related with the Date, I have the issue too with ArrayInput.
Did you find any workarounds?

@otroboe otroboe changed the title DateInput with warnWhenUnsavedChanges is triggering an alert when submitting the form DateInput or ArrayInput with warnWhenUnsavedChanges are triggering an alert when submitting the form Dec 4, 2020
@hacktisch
Copy link

My theory is that certain form fields dispatch a change event to the react-final-form state, when they are reinitialized after the entity is saved (the backend returns the current values of the saved entity, and fills those into the form).
Because the change is triggered, the react-final-form state gets the flag "dirty" or not "pristine" as it's called internally.
And React-Admin fires a browser location change to the react-router, albeit it to the same url path (if you are on /#/page/10, it redirects you to /#/page/10).
As you have warnWhenUnsavedChanges turned on, it protests against this "url change"

@lilit-melkonyan-im
Copy link

I have the same issue after updating the react-admin version from 3.8.2 to 3.11.2. It works for some FormWithRedirect forms and doesn't work for TabbedForms at all. Any news??

@djhi
Copy link
Collaborator

djhi commented Jan 15, 2021

See #5776 which should be released in next patch version

@fzaninotto
Copy link
Member

Fixed by #5776

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

6 participants