Can I use Asynchronous Blur Validation with redux-form on a hidden input field?

浪尽此生 提交于 2019-12-01 13:16:35

Yeah, asking how to do something when a hidden input blurs is like asking how to do something when your water is dry.

The concept of hidden inputs doesn't really exist in redux-form, as hidden inputs are based on the ye olde HTML way of submitting forms. A "hidden input" in redux-form is just a field that appears in the fields list (so it will be submitted), but that is not rendered to any input. I do this for primary keys, where my fields list is ['id', 'name', 'email'], and I only render inputs for name and email, but all three get submitted.

I think what you want is for your async validation to fire when a rendered (non-hidden) field is blurred, and for all of the fields, even the ones that are not rendered, to be passed to the async validation function. With the example above, something like this would work:

reduxForm({
  form: 'myForm',
  fields: ['id', 'name', 'email'],
  asyncValidate: doServerSideAsyncValidation,
  asyncBlurFields: ['name', 'email'] // both rendered fields will trigger async validation
})
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!