简体   繁体   English

错误:循环依赖,节点为:“dateA”

[英]Error: Cyclic dependency, node was:"dateA"

I want some information about the best implementation for a scenario like this: I have a select and two date pickers.我想要一些关于这样的场景的最佳实现的信息:我有一个选择器和两个日期选择器。 When I choose from the select (idRisk) the parameter PRESENT, the two dates must be required.当我从 select (idRisk) 参数 PRESENT 中选择时,这两个日期必须是必需的。 If DateA is before the DateB then in the form I want to show a validation error.如果 DateA 在 DateB 之前,则在表单中我想显示验证错误。 What is the best way to achieve this?实现这一目标的最佳方法是什么? I write this for completation, but show this error = Error: Cyclic dependency, node was:"dateA"我写这个是为了完成,但显示这个错误=错误:循环依赖,节点是:“dateA”

validationSchema: Yup.object({

idRisk: Yup.number().required(),

dateB: Yup.mixed().when("idRisk", {
is: Risk.PRESENT,
then: Yup.mixed().required(),
otherwise: Yup.mixed()
}),

dateA: Yup.mixed().when("idRisk", {
is: Risk.PRESENT,
then: Yup.mixed().required(),
otherwise: Yup.mixed()
})
.when(["dateA", "dateB"],
(dateA, dateB) => {
if (dateA.isBefore(dateB))
return this.required();
}
)
})

you cannot referrer the parameter ["dateA"] inside dateA:Yup.mixed().when() method, consider to use different approach, on example:您不能在dateA:Yup.mixed().when()方法中引用参数["dateA"] ,请考虑使用不同的方法,例如:

dateA: Yup.mixed()
  .when(["dateB"],
    (dateB, schema, node) => {
      if (node.value.isBefore(dateB))
        return this.required();
    }
  )

you can get dateA value from node.value您可以从node.value获取 dateA 值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM