You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would expect to not see the TextInput rendered on page load. This is because we don't display it if the BooleanInput is set to true, (which is its default value).
It seems that if an input has a defaultValue that value isn't applied to the formState immediately. The formState is only then updated once we change one of the form's inputs.
In addition to the formState not being up to date, it also means that the save button is disabled until we change one of the inputs, which shouldn't be the case if we've set default values on one or more of our inputs
A temporary work around is to set these values from within the Form's defaultValues object.
EDIT:
It seems that even with the temporary workaround, the save button is still disabled until we make a change to one of the inputs. My initial thought is that this not expected behaviour. For a good UX, we might want to set sensible defaults to our form, which our end-user could save without having to make any additional changes themselves.
I assumed that there may be a way to override this behaviour via the Form's props, but I can't see an attribute to override the SaveButton's disabled state. I figure I would need to pass through a custom save button with the alwaysEnable prop set to true.
Environment
React-admin version:
Last version that did not exhibit the issue (if applicable):
React version:
Browser:
Stack trace (in case of a JS error):
The text was updated successfully, but these errors were encountered:
andrico1234
changed the title
Default values aren't applied to the formState immediately
Input level default values aren't applied to the formState on mount
Apr 29, 2022
Regarding the Save Button's enabled state, I believe setting alwaysEnable to true is the simplest solution you can have, and it doesn't seem that unsuitable to me.
With code like this:
I would expect to not see the
TextInput
rendered on page load. This is because we don't display it if theBooleanInput
is set to true, (which is its default value).You can see this behaviour in the PostCreate page
It seems that if an input has a
defaultValue
that value isn't applied to the formState immediately. TheformState
is only then updated once we change one of the form's inputs.In addition to the formState not being up to date, it also means that the save button is disabled until we change one of the inputs, which shouldn't be the case if we've set default values on one or more of our inputs
A temporary work around is to set these values from within the
Form
'sdefaultValues
object.EDIT:
It seems that even with the temporary workaround, the save button is still disabled until we make a change to one of the inputs. My initial thought is that this not expected behaviour. For a good UX, we might want to set sensible defaults to our form, which our end-user could save without having to make any additional changes themselves.
I assumed that there may be a way to override this behaviour via the
Form
's props, but I can't see an attribute to override the SaveButton's disabled state. I figure I would need to pass through a custom save button with thealwaysEnable
prop set totrue
.Environment
The text was updated successfully, but these errors were encountered: