Inactivehelp wanted
描述
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]);