未在具有点语法名称的 Field 实例上标记 syncError
syncError not flagged on Field instance with dot syntax name
我有一个字段 poll.id,它是包含多个部分的表单的一部分。每个部分都包含在一个带有@reduxForm 注释的组件中,每个组件都可能有自己独特的验证方法。
我的问题是,在这种情况下,当 validatePoll returns 验证异常时,它不会出现在字段级别。我想知道这是否与字段的点语法有关。
@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 {
您遗漏了验证函数,但我猜您返回的是:
validate(values) {
const errors = {}
if(!values.poll.id) {
errors['poll.id'] = 'Required' // ❌
}
return errors
}
...你应该返回这个:
validate(values) {
const errors = {}
if(!values.poll.id) {
errors.poll = { id: 'Required' } // ✅
}
return errors
}
我有一个字段 poll.id,它是包含多个部分的表单的一部分。每个部分都包含在一个带有@reduxForm 注释的组件中,每个组件都可能有自己独特的验证方法。
我的问题是,在这种情况下,当 validatePoll returns 验证异常时,它不会出现在字段级别。我想知道这是否与字段的点语法有关。
@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 {
您遗漏了验证函数,但我猜您返回的是:
validate(values) {
const errors = {}
if(!values.poll.id) {
errors['poll.id'] = 'Required' // ❌
}
return errors
}
...你应该返回这个:
validate(values) {
const errors = {}
if(!values.poll.id) {
errors.poll = { id: 'Required' } // ✅
}
return errors
}