小编Ray*_*Man的帖子

错误:Yup 验证的循环依赖

我有这个 Yup 验证模式,其中包括对 min_amount 和 max_amount 值的检查。我在 ReactJS 表单上使用它。

const amountsSchema = yup.object({
  min_amount: yup.number()
    .max(999999999999999)
    .nullable()
    .transform((v, o) => (o === '' ? null : v))
    .typeError('min_amount must be a number')
    .when('max_amount', {
      is: '',
      then: yup.number().min(1),
      otherwise: yup.number().lessThan(yup.ref('max_amount'), 'min_amount must be less than maximum amount'),
    })
    .required(),

  max_amount: yup.number()
    .max(999999999999999)
    .nullable()
    .transform((v, o) => (o === '' ? null : v))
    .typeError('max_amount must be a number')
    .when('min_amount', {
      is: '',
      then: yup.number().min(1),
      otherwise: yup.number().moreThan(yup.ref('min_amount'), 'max_amount must be greater …
Run Code Online (Sandbox Code Playgroud)

javascript validation reactjs yup

7
推荐指数
1
解决办法
2万
查看次数

标签 统计

javascript ×1

reactjs ×1

validation ×1

yup ×1