如果是这样,如何正确传递字段名称以使其在组件内显示错误?
我下面的操作方式不起作用:
<FieldArray name='myFieldArray' component={renderArrayField} />
function onSubmit(values) {
values.myFieldArray.forEach((myField, index) => {
if (!myField.someText) {
const errorObj = {}
const myFieldName = "myFieldArray[" + index + "].someText"
errorObj[myFieldName] = 'Field required!'
throw new SubmissionError(errorObj)
}
})
// save the form
}
我也尝试过:
const myFieldName = "myFieldArray[" + index + "].someText._error"
和
const myFieldName = "myFieldArray[" + index + "]['someText']"
和
const myFieldName = "myFieldArray[" + index + "]['someText']['_error']"
但也没关系...
最佳答案
您需要使用深层对象来显示嵌套字段的错误。像这样:
const errorObj = {
myFieldArray: {
[index]: {
someText: 'Field required!'
}
}
};
throw new SubmissionError(errorObj);
关于javascript - SubmissionError是否适用于FieldArray字段?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46082614/