Как сделать валидацию двойной вложенности в redux form?
Есть следующая вложенность данных:
{
name: "name"
type: "type"
bodyStringified: [{
question: "string"
body: [{
value: "string",
isCorrect: true
}]
}]
}
и функция валидатор для FieldArray в redux form:
import get from 'lodash/get';
const validateArrayField = (errors, error, errorMatchedArrayRegExr) => {
const errorsObj = { ...errors };
const { path: errorPath } = error;
const arrayIndexWithBrackets = errorMatchedArrayRegExr[0];
const errorPathSplitted = errorPath.split(arrayIndexWithBrackets);
const errorsArrayPath = errorPathSplitted[0];
const errorFieldPath = errorPathSplitted[1].replace('.', '');
const arrayIndex = arrayIndexWithBrackets[arrayIndexWithBrackets.search(/\d/, '')];
errorsObj[errorsArrayPath] = get(errorsObj, errorsArrayPath, []);
const errorsArray = errorsObj[errorsArrayPath];
errorsArray[arrayIndex] = get(errorsArray, arrayIndex, {});
errorsArray[arrayIndex][errorFieldPath] = error.message;
return errorsObj;
};
export default validateArrayField;
и есть сама схема валидатора:
const QuizAdd = Yup.object().shape({
name: Yup
.string()
.trim()
.required(errorsText.required)
.min(3, 'Мінімум 3 символи'),
type: Yup
.string()
.required('Оберіть тип'),
bodyStringified: Yup
.array()
.of(Yup.object().shape({
question: Yup
.string()
.trim()
.required(errorsText.required)
.min(3, 'Мінімум 3 символи'),
body: Yup
.array()
.of(Yup.object().shape({
value: Yup
.string()
.trim()
.required(errorsText.required)
.min(3, 'Мінімум 3 символи'),
isCorrect: Yup.string().trim().required('Оберіть варіант'),
})
.uniqueProperty('value', errorsText.unique('Це поле'))
.required(errorsText.required)),
}))
});
не могу понять как сделать валидацию для вложенности в body. То есть, итемов в bodyStringify может быть n-количество, так же в body их может быть n. Валидация name, type, question работает корректно, а body не видит.