-
-
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
warnWhenUnsavedChanges does not function properly with disabled inputs #9498
Comments
Thanks for the detailed report. As you saw, this issue finds its root in a decision made by the At the moment I'm not sure what solutions we can offer for this problem. But, since we don't have a fix nor a workaround for all cases, I think we should consider this as a bug. Any help or suggestion are appreciated. |
I understand that it is RHF that changed the logic to set disabled fields to undefined, changing the original value and making the form dirty. Is there a possibility that:
That way, we can still use the regular |
These are good suggestions, thanks! I'd also add the following one:
Indeed, semantically, for this use case where we want the input to be immutable but still submitted, |
@lvernaillen It seems to me that #9527 actually allows to apply the workaround I suggested here, which fixes this issue. Can you confirm? |
I'm afraid that doesn't work. An I created a new stackblitz with react-admin 4.16.3 containing #9527. |
Same for For |
Thanks @lvernaillen for the feedback. |
Fixed by #9656 |
What you were expecting:
What happened instead:
disabled
, others should useInputProps
workaround and other don't have a clear workaround.Related code:
AutoCompleteInput
exposes the warnWhenUnsavedChanges bughttps://stackblitz.com/edit/github-ny4hdu?file=src%2Fposts%2FPostEdit.tsx,src%2Fposts%2FPostList.tsx,src%2Fposts%2FPostShow.tsx
AutoCompleteInput
https://stackblitz.com/edit/github-6a8auj?file=src%2Fposts%2FPostEdit.tsx
AutoCompleteInput
is not disabled although it has theInputProps
setAutoCompleteInput
looks as if enabled, but is not (because readonly)TextInput
behave correctly with theInputProps
workaroundArrayInput
readonly but still able to add / remove itemsOther information:
We have this situation a lot. Our edit pages disable certain inputs when the logged on user has no permission to change them. But now they get a confusing warning about unsaved changes when the form was untouched.
I already mentioned this in the closed related issue #9378. There a workaround is described for the
TextInput
component by using theInputProps
to set disabled instead of directly using thedisabled
prop.However that only works for a
TextInput
. Other inputs expose that same bug without having the workaround.AutoCompleteInput
: has this bug, has InputProps, but the workaround does not workAutoCompleteArrayIput
andArrayInput
: have this bug, have no InputProps so the workaround does not workBooleanInput
: does not have this bug, so disabled can be usedSo some components do not expose the bug, others expose the bug but have a workaround using
InputProps
and again others have no clear workaround with props. For those without prop workaround we might wrap them in a div and set the div disabled while adding some styling (pointer-events, color, MuiInputBase-root) to simulate a disabled input.So it's a bit messy currently. When something needs to be disabled we need different kinds of solutions per input.
In #9378 @slax57 suggested using
readonly
.However that does not work on an
ArrayInput
for example, you can still change it. For anAutoCompleteInput
thereadonly
prop results in a component that looks as if you can change it, but actually you can't. Users think something is broken without the visual feedback of being greyed out, which thedisabled
prop does give. Soreadonly
is not really an alternative.Related issues:
#9365
react-hook-form/react-hook-form#11055
Environment
The text was updated successfully, but these errors were encountered: