redux-form - asyncBlurFields with FieldArray Component

泄露秘密 提交于 2019-12-24 08:28:19

问题


I'm wondering how to get async validation to trigger on a Field component inside of a FieldArray. I have something like:

class MyForm extends Component {
  constructor(props) {
    super(props)

  }

  render() {
    const { handleSubmit } = this.props

    return (
      <form onSubmit={handleSubmit}>  
        <Field
          name="name"
          type="text"
          component={RenderInputField}
        />
        <FieldArray
          name="hobbies"
          component={RenderHobbies}
        />
      </form>
    )
  }
}

MyFormBase = reduxForm ({
  form: 'MyForm',
  validate,
  asyncValidate,
  asyncBlurFields: ['name', 'hobbies.hobby']
})(MyFormBase)

With RenderHobbies as:

const RenderHobbies = ({fields}) => (
  <div>
    {fields.map((hobby, index) => ({
      <Field
        name={`${hobby}.hobby`}
        component={RenderInputField}
      />
    }))}
  </div>
)

export default RenderHobbies

This doesn't work. async validation will fire for "name" on blur but not "hobbies.hobby". What would the correct syntax for that be?


回答1:


The syntax I was looking for was:

asyncBlurFields: ['hobbies[].hobby']

Pretty simple, I just couldn't find it anywhere in the docs. I found it by going through this thread



来源:https://stackoverflow.com/questions/46185022/redux-form-asyncblurfields-with-fieldarray-component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!