reactjs - 是的,对具有相同名称的动态表单进行验证
问题描述
我在 React 中有一个表单,我可以动态添加/删除 Min/Max 输入。我正在尝试验证每一行,inputMin
应该少于我的inputMax
架构。仅当两个输入字段都不为空时才应用验证。react hook form
yup
const validationSchema = yup.object().shape({
inputMin: yup
.when("inputMax", {
is: v => v > 0,
then: number().lessThan(ref("inputMax"), "Min should be less than Max")
})
});
const { register, triggerValidation } = useForm({ validationSchema });
用户动态添加/删除的 React 组件中的 HTML:
<input name="inputMin" type="number" ref={register} />
<input name="inputMax" type="number" ref={register} />
这在只有一行 Max/Min 时有效。但是当有 2 行时,它不能很好地验证。
MIN MAX
ROW1 : 0 5
ROW2 : 9 5 <-- (the triggerValidation doesn't catch this error)
我怎样才能告诉它正确地验证每一行inputMin
的兄弟姐妹?inputMax
解决方案
推荐阅读
- android - 约束布局中的多文本视图
- go - 添加新的实现而无需触及现有代码 - 如何?
- c# - 在 wpf 中,我可以使用 SHDocVw 打开 InternetExplorer 以访问 HTMLDocument。需要进行 Microsoft Edge 迁移
- javascript - html输入框最小值和十进制值
- firebase - 测试 Firebase 的“https.onCall”函数
- windows - 玩完第一轮游戏就崩溃了,我怎样才能让它正常运行?
- php - 如何添加仅出现在 WooCommerce 商店页面上的小部件
- java - Java JaCoCo 覆盖率报告中的部分覆盖率
- java - Swagger API 规范 - 自定义 API 响应属性 usign @ApiPropertyModel
- firebase - Firebase 在 Flutter Web 上无法运行,但在 android 模拟器上运行良好