-
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] Add updateImmediately prop & fix handleChange #109
Conversation
4708bf1
to
5affb7d
Compare
Accepts Formsy.Form.reset()
👍 |
- Make sure that both value and defaultValue can be provided. - Make sure that changing the props and resetting the form works. - Also fix reset to work, when value and defaultValue are not specified. - Only update the pristine value, but not the actual value, in case props.defaultValue has changed. - Add tests for value and defaultValue props interactions. - Remove previous componentWillReceiveProps which targeted to fix reset. Also, update peer dependency
Fix text input values, and form reset
Works great for me so far, but I think that |
Fixes React 15.2 unknown props warnings. Closes #119.
Agreed that throttle seems to make more sense for this use case. I'd love to see this pull request get merged as I've been dealing with the "last text input in a form not enabling the submit button" issue for quite some time and it really does cause confusion for some users. Is there something I can do to help? |
I see. Throttle seems to be better for this case. What is status of this pull request? |
@codeaholicguy It needs a rebase after recent merges. I can see pros and cons to throttle vs. debounce, but I'm not yet convinced that throttle would be preferable. I'm open to feedback as to why. With throttle, a slower typist is going to get an error when their going-to-be-valid, but as yet incomplete entry hits the throttle timeout. With debounce, a fast typist doesnt get an error until they're done, but if they're a fast typist, they can fix thier error quickly. 😄 |
When we agree on the best approach, you're welcome to take this PR, fix it up and resubmit it. |
@mbrookes I hear ya, and I could certainly be happy with either. I think the reason this is a tough call is we have two use cases for the updateImmediately prop:
If I had to choose one, the latter seems more useful. My guess is accomplishing both effects would require some non-trivial internal changes, but perhaps we could provide the two versions separately via two different props?? So updateImmediately would provide a throttled version and another prop, say updateWhenIdle, would provide a debounced version? |
Having the choice via a prop would be good, but what should the default be? 😄 |
Hi, Any news on this one ? Many thanks. |
@mbrookes can I take responsibility of rebasing this PR?
|
@codeaholicguy Yes please!!! |
@mbrookes I rebased |
Thanks @codeaholicguy! I'm merging this as is, as I don't have the cycles to review right now, but since this is mostly based on your code, I know it's good! I think it would be good to get community feedback before we release, so lets hold back on pushing to npm for a bit and see if this throws up any issues. BTW, I gave you write access to the repo, so feel free to make other changes, or merge good PRs. |
@mbrookes thank you! Should I merge this PR or wait for you? |
Oops! In my haste I forgot to confirm the merge. Done now. |
I'm using this
|
@rojobuffalo currently, it hasnt been tagged yet, so please use |
Hi, thanks for this PR. Could you explain why you added a debounce? @jayalfredprufrock Could you explain how a user gets bombarded by error messages? Either the input is already invalid, so the message is already shown under the textfield or the input gets invalid, and as soon as this happens I want to know about and not wait for 400ms. |
The debounce behavior becomes desirable when you have an input that is guaranteed to fail validation at the first key stroke. Consider a password confirmation field or an email field. It's a little distracting to see the flash of an error message telling you your password is incorrect or email invalid when you just haven't had a chance to finish typing. In a perfect world, the user would be notified immediately when the field becomes valid, but only notified of invalid input after a short idle period. Earlier I was suggesting some kind of "updateWhenIdle" type functionality where the field can only be invalidated after it has received focus and at least one character, and the user hasn't typed any thing in 400ms. Haven't had a chance to look at the above implementation to know how things are supposed to work now, but it sounds like either way this is a nice improvement to what we had before. |
@jayalfredprufrock I like the ideal world ^^, maybe following merge request goes into this direction: #155 |
I believe this resolves the various issues for both use cases. Let me know!
This is based in part on and supersedes @codaholicguy's PR: #103.
If you use
onValid
/onInvalid
to control the submit button, and the last form element before the submit button is a text-field, you should useupdateImmediately
on that field to provide an error as to why the form can't be submitted without the user having to remove focus from that field.I increased the timeout slightly, as otherwise the error can come in while still typing for a slower typist.
If you don't control the submit button (or the textfield isn't the last value before the button), the default behaviour is now consistent.
onValid
/onInvalid
update immediately, but the error only appears when focus shifts.Closes #97.