syncError not flagged on Field instance with dot syntax name

久未见 提交于 2019-12-25 07:36:06

问题


I have a Field poll.id that is part of a form that contains multiple parts. Each part is contained in a component with a @reduxForm annotation and each component may have it's own unique validation method.

My problem is that in this case, when the validatePoll returns a validation exception, it doesn't show up at Field level. I wonder if this has to do with the dot syntax of the field.

@reduxForm({
    form: 'posteditor',
    destroyOnUnmount:false,
})
@autobind
class MyForm extends React.Component {

    [...]

    pollButton(field){
        console.log('poll.id', field);//meta.error = undefined
        [...]
    }


    poll(){
        const { poll, visible, syncErrors } = this.props;
        return (
          <Field
            name="poll.id"
            value={poll && poll.id}
            type="number"
            component={this.pollButton}
            props={{
              visible: visible,
              questions: (poll && poll.questions) || []
            }}
            />
        );
    }
}


@reduxForm({
    form: 'posteditor',
    validate: validatePoll,
    destroyOnUnmount:false,
})
@autobind
class PostPoll extends React.Component {


回答1:


You left out your validation function, but my guess is that you are returning this:

validate(values) {
  const errors = {}
  if(!values.poll.id) {
    errors['poll.id'] = 'Required' // ❌ 👎
  }
  return errors
}

...and you should be returning this:

validate(values) {
  const errors = {}
  if(!values.poll.id) {
    errors.poll = { id: 'Required' } // ✅ 👍
  }
  return errors
}


来源:https://stackoverflow.com/questions/40704827/syncerror-not-flagged-on-field-instance-with-dot-syntax-name

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