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

On edit form, useUnique fetches currently edited record and prevents saving #9111

Closed
bjab opened this issue Jul 19, 2023 · 3 comments · Fixed by #9118
Closed

On edit form, useUnique fetches currently edited record and prevents saving #9111

bjab opened this issue Jul 19, 2023 · 3 comments · Fixed by #9118
Labels

Comments

@bjab
Copy link

bjab commented Jul 19, 2023

What you were expecting:
What happened instead:
We have edit form, where one of fields has unique validator - in our case resource should have unique name.
We change one of other resource fields and try to save, but name field is marked as invalid as already existing, although it did not change.
I see, that query returns currently edited record and that's why it fails.

Other information:
I see two ways of solving this (in our case):

  1. do not run validation if field did not change
  2. somehow pass filter like id <> currentRecord.id, but I don't have idea, how to do it as json object
  3. when checking server response, if it contains only one record and id matches current, then pass validation

Environment

  • React-admin version: 4.12.1
  • React version: 18.2.0
  • Browser: chrome
@djhi
Copy link
Collaborator

djhi commented Jul 19, 2023

Thanks for reporting this. Please provide a sample application showing the issue by forking the following Stackblitz (https://stackblitz.com/github/marmelab/react-admin/tree/master/examples/simple).

@bjab
Copy link
Author

bjab commented Jul 21, 2023

Thanks for reporting this. Please provide a sample application showing the issue by forking the following Stackblitz (https://stackblitz.com/github/marmelab/react-admin/tree/master/examples/simple).

Hi
https://stackblitz.com/edit/github-awixt5?file=src%2Ftags%2FTagEdit.tsx
I made tag names unique

Steps to reproduce:

  1. go to tags and edit one of them
  2. add FR entry
  3. go to EN tab
  4. click save

Validation will fail, even that EN name was not changed

@djhi
Copy link
Collaborator

djhi commented Jul 21, 2023

Ah I see now. Good catch, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants