Redux-form 6.0.0 access error outside Field component

前端 未结 2 1614
悲哀的现实
悲哀的现实 2021-01-06 17:27

In Redux-form v5 I was able to access to the \"inline\" errors (async validation) from anywhere in the decorated form, like so:

const fields = [
  \'email\'
         


        
2条回答
  •  时光取名叫无心
    2021-01-06 17:49

    If you are wanting to display the error next to the input, then it should be handled in the component that you pass to Field. If you want to display all the errors together, like at the bottom of the form by the submit button, you could use the new Fields component like so:

    const fieldNames = [
      'email',
      'password'
    ]
    
    const renderAllErrors = fields => (
      
      {Object.keys(fields).map(key => { const { meta: { touched, error } } = fields[ key ] return touched && error ?
    • {key}: {error}
    • : undefined })}
    ) ...

提交回复
热议问题