如何使用yup验证嵌套对象的要求

时间:2019-03-21 13:29:51

标签: javascript reactjs yup

surveyCategories是一个既包含字符串又包含对象的数组。我只想使用Yup验证此数组。验证条件在if条件下给出。

const surveyCategories = values.surveyCategories
  .filter(value => !value.sub.subId)
  .map(catId => value, 10);

const subCategories = values.surveyCategories
  .filter(value => value.sub.subId)
  .map(value => ({
    id: value.sub.value,
    intakeTypeId: value.sub.typeId,
    intakeSubTypeId: value.sub.subId
  }));

if (surveyCategories.includes(4) && !subCategories.length) {
  console.log("Select atleast one intake to link with survey!");
}

0 个答案:

没有答案