我的表单上有一个 MUIRadioGroup(选项 = 低、中和高)和一个多选 MUIAutocomplete 组件。
<MUIRadioGroup
name="requestDetail.riskAssesmentDetail.riskClassification"
label="Risk Classification"
variant="outlined"
size="small"
defaultValue
/>
<MUIAutocomplete
name="requestDetail.riskAssesmentDetail.safetyDetail.investigationType"
label="Type of Investigation"
variant="outlined"
size="small"
multiple
disableCloseOnSelect
options={API_Safety_InvestigationType}
/>
Run Code Online (Sandbox Code Playgroud)
我的架构是...
requestDetail: yup.object().shape({ ...
riskAssesmentDetail: yup.object().shape({
riskClassification: yup
.string()
.label("Risk Classification")
.required()
.typeError("Invalid Selection"),
safetyDetail: yup
.object()
.shape()
.when("riskClassification", {
is: (riskClassification) =>
["Medium", "High"].includes(riskClassification),
then: yup.object({
investigationType: yup
.array()
.label("Type of Investigation")
.min(1),
}),
}),
}),
Run Code Online (Sandbox Code Playgroud)
当单选按钮为“中”或“高”时,我需要对 MUIAutocomplete 组件执行验证。
我收到错误...
Uncaught (in promise) TypeError: branch is not a function
at Condition.fn (index.esm.js:175:1)
at Condition.resolve …
Run Code Online (Sandbox Code Playgroud)