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
The way formsy-react is built, the text field is assumed to have a _value in its state that is modified by setValue() and retrieved with getValue(). However, the implementation here of FormsyText holds its own state variable value that represents the displayed state of the text input. So in order to set the displayed and backing value of the FormsyText you actually need to call both setValue and setState.
As far as I can tell, the reason for the separate value (in addition to _value from the mixin) is to give the behavior that validation does not run until the user pressed enter or the form element lost focus.
I think the better way to implement the same functionality is to let _value be the source of truth (as the formsy-react docs recommend), and then conditionally do a setState call to update it, bypassing the typical validation code. I've already made this change in my fork of this project: astonm@75d130f
Happy to turn it into a PR here if the maintainers like the approach.
The text was updated successfully, but these errors were encountered:
Related to comment in #174, I think you should expose setValue for FormsyText which will wrap TextFieldsetValue function and setState of controlled component instead of doing like that.
@rojobuffalo @mbrookes what do you think if we reopen this issue and revert that pull-request?
The way
formsy-react
is built, the text field is assumed to have a_value
in its state that is modified bysetValue()
and retrieved withgetValue()
. However, the implementation here ofFormsyText
holds its own state variablevalue
that represents the displayed state of the text input. So in order to set the displayed and backing value of theFormsyText
you actually need to call bothsetValue
andsetState
.As far as I can tell, the reason for the separate
value
(in addition to_value
from the mixin) is to give the behavior that validation does not run until the user pressed enter or the form element lost focus.I think the better way to implement the same functionality is to let
_value
be the source of truth (as theformsy-react
docs recommend), and then conditionally do asetState
call to update it, bypassing the typical validation code. I've already made this change in my fork of this project: astonm@75d130fHappy to turn it into a PR here if the maintainers like the approach.
The text was updated successfully, but these errors were encountered: