-
Notifications
You must be signed in to change notification settings - Fork 149
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
[FormsyText] Warning: Input elements must be either controlled or uncontrolled #82
Comments
This also produces the following warnings in Chrome, when I try to set the
Setting using React 15.0.1 and Material UI 0.15.0-beta1 |
yep, I delete only one line on formsytext defaultValue: this.props.value and it works normally now, I can use defaultValue property |
@keremciu Can you make a pull request for that? It would be great. |
Hi there, I've created #87 which is a related issue, closing now because the two issues interrelate. In my original problem I passed in 'value' which I wanted to get passed down as defaultValue to TextField. This makes the field uneditable. I attempted to fix this in PR #86, which makes the field editable again. - But it also breaks the possibility to pass in a value directly. In my use, I don't do that, but reading this issue, I realize it can be a legitimate need.
However if everything is left as it is currently, it is not possible to set a defaultValue, and an intention to do so will actually set value instead of defaultValue, resulting in an uneditable form field. So a change is needed in any case, because passing in an initial value (transformed into defaultValue) is a legitime use case. It broke my codebase, for example, which was the main reason for me to figure out a solution. I beleive this line in the README: |
Looking deeper at this, the case seems more and more complex. I am not sure if some recent change in formsy, or the react update has caused the regression that does not allow the value to be changed any more. The only way I can make this work currently, if I start managing the value myself. I have a terribly messed up version that works for my code, but not elegant and workaround-ish. I'll consider another PR once I am able to stabilize things. |
@reebalazs - the reason the default value has to be set with Things may have been broken by the removal in 0.4.0 of a chunk of code to improve performance, (effectively a copy #72 applied manually). |
Actually, it's likely this was always an issue, but React didn't complain before 15.0. Could you try the current master? |
Before https://github.com/mbrookes/formsy-material-ui/pull/72/files the element was manually applying the newly input values to the underlying text element...now that it is removed you cannot use value/defaultValue at all without rending the textfield unchangeable. The warning about controlled/uncontrolled input elements is a separate (related) issue. Shouldn't cf19f38 be rolled back until a working solution can be found? |
@dmhood You shouldn't be using |
@mbrookes What I mean is using the value prop to set the default value (https://github.com/mbrookes/formsy-material-ui/blob/master/src/FormsyText.jsx#L34). It "locks" the value to whatever you pass in. There is no way to set the value but still get new user input. |
@dmhood - my bad. Missed the most important file from the commit! Try now. |
@mbrookes works great w/ the recent commit, thanks! edit: Leaving it open in case there is any more discussion but feel free to close. |
Gentlemen's, is there any workaround to use controlled inputs ? |
@dmhood - 0.4.1 released. @ochervak - not at the moment - controlled use was causing performance problems, but we'll have to revisit at some point, as uncontrolled use is possibly being removed from MUI in the future. Feel free to submit a PR if you can figure out a solution! 👍 |
thanks |
thanks! |
I've updated |
It took me a while but I tested the last fix out. The fix was definitely going to the right direction, very similar to my previous solution, but better. However it was still not perfect. Here is PR #100 which fixes the remaining problems. (Wohoo, PR 100!)
Some other notes are on the PR. Please test it out and let me know what you think, I am testing this for a while in a project, and it works well. |
Currently the defaultValue prop of the underlying TexField component is set using the "value" prop (https://github.com/mbrookes/formsy-material-ui/blob/master/src/FormsyText.jsx#L34). Because we pass all these props down to textfield (https://github.com/mbrookes/formsy-material-ui/blob/master/src/FormsyText.jsx#L32) this unfortunately makes the field un-editable. Suggest just removing https://github.com/mbrookes/formsy-material-ui/blob/master/src/FormsyText.jsx#L34 altogether.
The text was updated successfully, but these errors were encountered: