gpt4 book ai didi

javascript - 错误 : Cyclic dependency, 节点为 :"dateA"

转载 作者:行者123 更新时间:2023-12-05 00:38:34 25 4
gpt4 key购买 nike

我想要一些关于这种场景的最佳实现的信息:
我有一个选择器和两个日期选择器。
当我从选择 (idRisk) 参数 PRESENT 中选择时,这两个日期必须是必需的。
如果 DateA 在 DateB 之前,那么我想在表单中显示验证错误。
实现这一目标的最佳方法是什么?
我写这个是为了完成,但显示这个错误=错误:循环依赖,节点是:“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()
})
})

最佳答案

您不能引用参数 ["dateA"]里面 dateA:Yup.mixed().when()方法,考虑使用不同的方法,例如:

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

您可以从 node.value 获取 dateA 值

关于javascript - 错误 : Cyclic dependency, 节点为 :"dateA",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54804718/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com