-
-
Notifications
You must be signed in to change notification settings - Fork 53.3k
Open
react-component/field-form
#729Labels
Inactivehelp wantedThe suggestion or request has been accepted, we need you to help us by sending a pull request.The suggestion or request has been accepted, we need you to help us by sending a pull request.
Description
Reproduction link
Steps to reproduce
What is expected?
当rules为空数组时,能正确的将错误信息去掉
What is actually happening?
当rules为空数组时,无法移除已经校验的错误信息
Environment | Info |
---|---|
antd | 4.24.16 |
React | 17.x |
System | mac os |
Browser | chrome |
经过断点排查发现这个错误来自rc-form-field/src/useForm.ts#904 当rule为空时,无法不再触发校验逻辑。 代码如下
目前的临时解决方案
/**
* 空规则标识
* gai
*/
const EMPTY_RULE_SYMBOL = Symbol('EMPTY_SYMBOL');
/**
* 为了规避rc-form-field的校验bug
* 具体代码可以参考rc-form-field/src/useForm.ts#904
* @returns
*/
export const createEmptyRule = (): any => {
return {
[EMPTY_RULE_SYMBOL]: true,
};
};
// 需要为空时
setRules([createEmptyRule]);
Metadata
Metadata
Assignees
Labels
Inactivehelp wantedThe suggestion or request has been accepted, we need you to help us by sending a pull request.The suggestion or request has been accepted, we need you to help us by sending a pull request.