有办法让设置为 hidden 的字段在 submit 的时候进行 validate 嘛? #3174
Answered
by
janryWang
MinuteWong
asked this question in
Q&A [2.x]
-
https://codesandbox.io/s/goofy-brattain-kpwm8d?file=/App.tsx |
Beta Was this translation helpful? Give feedback.
Answered by
janryWang
Jun 13, 2022
Replies: 2 comments 4 replies
-
没有,这种不太符合直觉,也会导致后面维护成本很高,最好是提交时自己手工校验吧 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
janryWang
-
我们也有这种需求,专门基于源码写了个函数 // 强制校验
export const batchValidateForce = async (
target: Form | Field,
pattern: FormPathPattern = '*',
triggerType?: ValidatorTriggerType,
) => {
if (isForm(target)) target.setValidating(true);
// else {
// if (target.pattern !== 'editable' || target.display !== 'visible') return;
// }
const tasks = [];
target.query(pattern).forEach(field => {
if (!isVoidField(field)) {
//@ts-ignore
tasks.push(validateSelf(field, triggerType, field === target));
}
});
await Promise.all(tasks);
if (isForm(target)) target.setValidating(false);
if (target.invalid) {
notify(target, LifeCycleTypes.ON_FORM_VALIDATE_FAILED, LifeCycleTypes.ON_FIELD_VALIDATE_FAILED);
throw target.errors;
}
notify(target, LifeCycleTypes.ON_FORM_VALIDATE_SUCCESS, LifeCycleTypes.ON_FIELD_VALIDATE_SUCCESS);
}; |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
没有,这种不太符合直觉,也会导致后面维护成本很高,最好是提交时自己手工校验吧