How to re-trigger validations manually in ReduxFor

2019-02-18 00:57发布

I like to re-trigger validations after the form has mounted. Let's assume I like to run the validations each time I click a button named 'validate inputs'.

How to do this?

Related questions:

标签: redux-form
3条回答
放我归山
2楼-- · 2019-02-18 01:38

The sync validation is run on every render, so "triggering it" doesn't really have much meaning.

If you would like to use async validation, there is a this.props.asyncValidate() function that you can call to trigger it.

OR, if you prefer submit validation, you could just submit the form.

查看更多
劫难
3楼-- · 2019-02-18 01:52

According to 28/11/2018:

https://redux-form.com/6.2.1/docs/api/actioncreators.md/

There are actions that you can dispatch for making changes to your form and triggering the validation method.

If you trigger change/touch actions it should execute the validate function.

查看更多
仙女界的扛把子
4楼-- · 2019-02-18 02:00

Manual redux-form validation is an oft requested feature, that does not seem to be provided at the moment.

My personal workaround is to trigger this.props.change('_validationHack', Date.now()) in the reduxForm-wrapped component and then remove values._validationHack in the onSubmit method before sending the values to the server.

It's not pretty, but seems to work without exception.

查看更多
登录 后发表回答