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

后端 未结 1 1890
难免孤独
难免孤独 2021-01-16 01:52

I have a redux-form specific question.

I have a hidden input in my form:


And would like

1条回答
  •  不思量自难忘°
    2021-01-16 02:10

    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
    })
    

    0 讨论(0)
提交回复
热议问题