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

Ability to reset a field when submitting finished with error #3380

Closed
unconfident opened this issue Sep 5, 2017 · 2 comments
Closed

Ability to reset a field when submitting finished with error #3380

unconfident opened this issue Sep 5, 2017 · 2 comments

Comments

@unconfident
Copy link

Are you submitting a bug report or a feature request?

It's a feature request

Let's say I have a captcha field. When server rejects the form for whatever reason the captcha needs to be cleared and refreshed. It would be nice if redux-form was able to reset the field back to its initial value every time submitting finished with error. To do that right now it would require a special-crafted onSubmit handler which makes it harder to use the form in the scenarios where this handler should be passed down through props. Now it can be done by tracking changes in submitting and submitFailed props of the form in the form component, but that seems unnecessary complicated.

Ideally I would want to be able to add or remove fields like that captcha I used as example without having to heavily modify the form itself. I like my forms as functional components

Proposed API:

const MyForm = ({ handleSubmit }) => (
    <form onSubmit={handleSubmit}>
        <Field name="comment" component="input" type="text" />
        <Field component={CaptchaField} name="captcha" resetOnSubmitFail />
        <button>Submit</button>
    </form>
)

And then captcha field could be stateful component that would reload itself every time it changes from dirty to prestine... Which can also happen if user just clears the value. Damn

Does this make any sense?

@gustavohenke
Copy link
Collaborator

Detecting changes from dirty to pristine and back to dirty seems over complicated!

I think your issue is quite specific and it can be done more easily if you dispatch an action that increases a counter. Everytime your counter changes, you can render your captcha.
This is possible via onSubmitFailed config.

@lock
Copy link

lock bot commented Oct 13, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 13, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants