【发布时间】:2021-10-20 02:03:08
【问题描述】:
我将 react-hook-form 6.8.2 与 React 16.13.1 一起使用,正常验证按预期工作,但在“验证”键内时无效。
const { trigger, formState, watch, reset } = useFormContext({
mode: 'all',
});
--
ref={register({
required: 'This is required',
minLength: {
value: 3,
message: 'Length must be 3 or more',
},
validate: {
always: (value) => value === 1 || 'This should almost always trigger',
},
maxLength: {
value: 5,
message: 'max 5',
},
})}
required、minLength 和 maxLength 都可以工作,但 always 不行。
我试过这个:
always: (value) => value === 1 || console.log('This should almost always trigger') 在控制台中记录错误
我已经尝试过了:validate: (value) => value === 1 || 'This should almost always trigger' 也没有任何作用
为什么 UI 中没有显示验证消息?
【问题讨论】:
-
您能否提供一个包含最小可复制示例的代码框以及预期结果应该是什么?
标签: reactjs react-hooks react-hook-form