Repository navigation
Cannot pass a defaultValue to the controllable components #542
Unanswered
samantagavare
asked this question in
Q&A
Replies: 1 comment
|
Thanks for your submission. I've converted this to a discussion since I'm not sure this is an issue right now. I looked at your codesandbox and it isn't clear to me why you aren't using initialValues.planet=['mars'] |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Describe the bug
Restoring values from browser session storage or somewhere else to a controllable Autocomplete/TextField/etc. component is not possible using defaultValue or value parameters. Providing initialValues to the react-final-form Form component also does not work (values are not be visible inside fields). Providing a non-empty value to the component and filled initialValues to the form does work, but it is difficult to maintain these values separately and it is not possible to mark the fields as dirty. In Material-UI, the defaultValue parameter is only used for uncontrollable component, but if the react-final-form Field allows to specify the defaultValue, why not to use it?
Workaround for Autocomplete component
defaultValue={rest.defaultValue}after
mui-rff/src/Autocomplete.tsx
Line 51 in 0ba99ae
To Reproduce
Result: Autocomplete field is empty.
Expected result: Autocomplete field should have a value of 'Mars' and form field data should have a key "planet" with value [
"mars"
].
Desktop
All reactions