Skip to content
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

Calling setValue on FormsyText doesn't work #161

Open
astonm opened this issue Nov 16, 2016 · 3 comments
Open

Calling setValue on FormsyText doesn't work #161

astonm opened this issue Nov 16, 2016 · 3 comments

Comments

@astonm
Copy link
Contributor

astonm commented Nov 16, 2016

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.

@codeaholicguy
Copy link
Collaborator

Related to comment in #174, I think you should expose setValue for FormsyText which will wrap TextField setValue 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?

@ryanblakeley
Copy link
Collaborator

@codeaholicguy agreed. should we revert and tag v0.5.5 so @latest works?

@ryanblakeley ryanblakeley reopened this Feb 9, 2017
@codeaholicguy
Copy link
Collaborator

@rojobuffalo yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants