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

Be able to trigger validation manually #3992

Open
Sajam opened this issue Apr 20, 2018 · 8 comments
Open

Be able to trigger validation manually #3992

Sajam opened this issue Apr 20, 2018 · 8 comments
Labels
enhancement improvements in current API help wanted

Comments

@Sajam
Copy link

Sajam commented Apr 20, 2018

Are you submitting a bug report or a feature request?

Feature Request

What is the current behavior?

I want to enable/disable some button (outside the form), depending on whether my form is valid or not (sync validation). The thing is, that after I reset the form (using reset action creator) it identifies as valid (using isValid selector) and there's no possibility to run validation on this form manually.

What is the expected behavior?

Be able to run validation (and choose sync or async?) on a form manually using action creator.

What's your environment?

Redux Form: 7.2.0

Thanks!

@gustavohenke gustavohenke added enhancement improvements in current API help wanted labels Apr 25, 2018
@gustavohenke
Copy link
Collaborator

I'm pretty sure this was asked before, but I couldn't find the original issue yet.

@Sajam
Copy link
Author

Sajam commented Apr 26, 2018

@gustavohenke - Here's the one, but it's a bit different -- they want to use it inside the form, where handleSubmit is available, which is not a case here (and it also require to use not so elegant hack): #960. I hope that this is the one you were thinking about?

Also, tricks with triggering fake submit, blurring/changing the fields aren't convincing me, those are just hacks. If there's startAsyncValidation action creator, it would be nice (and logical) to have startSyncValidation or general validate. What are your thoughts?

Thanks! :-)

@gustavohenke
Copy link
Collaborator

Hm, perhaps what I remember people asking was some way to set the errors, which is... essentially the same as running the validation.

So yeah, I think having this consistency among the action creators would be cool 👍

@danielrob
Copy link
Collaborator

@gustavohenke perhaps #3267.

@JasonNutmeg
Copy link

I wanted to mention two things that might help with your original question ( and also for anyone who's reading this at a later point).

  1. There's a list of action creators that are exposed by redux-form. In particular, you could trigger the blur() or touch() action on the button in order to update its touched state.
  2. The clearFields() function accepts a keepTouched boolean as its 2nd argument so that you don't reset the touched state on the fields you clear.

@prakashsvmx
Copy link

+1

@moffsugita
Copy link

I wanna do validation when form appeared like edit page.

@AleksandrSidorov
Copy link

AleksandrSidorov commented Nov 15, 2019

To get the syncErrors on reset() you can use this configuration:

reduxForm({
    form: formName,
    validate,
    shouldError: () => true,
  })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement improvements in current API help wanted
Projects
None yet
Development

No branches or pull requests

7 participants