Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛[BUG] validateTrigger="onBlur" validation not working #8380

Open
Ladvace opened this issue May 3, 2024 · 4 comments
Open

🐛[BUG] validateTrigger="onBlur" validation not working #8380

Ladvace opened this issue May 3, 2024 · 4 comments

Comments

@Ladvace
Copy link

Ladvace commented May 3, 2024

I tried to apply a validateTrigger="onBlur" on a ProForm.Item but the validation doesn't seems working, I'm using it on a stepForm

Copy link

github-actions bot commented May 3, 2024

以下的 Issues 可能会帮助到你 / The following issues may help you

@SANmq
Copy link
Contributor

SANmq commented May 18, 2024

validateTrigger 为 onBlur没生效的原因找到了。因为源码中有一个WithValueFomFiledProps组件分隔了form.item和表单组件间的props传递。其中有一个判断
const isProFormComponent = // @ts-ignore filedChildren?.type?.displayName !== 'ProFormComponent';
如果为false的话会导致很多props不会透传给antd的form.item。这个干嘛用的不太清楚。
所以解决方案可以是给自己自定义的组件加上 displayName ="ProFormComponent" 属性就能解决。
不过这个应该不是最终解决方案,还是得看它原来是要干嘛
@chenshuai2144

@SANmq
Copy link
Contributor

SANmq commented May 18, 2024

重新看了一下就是onBlur没有传进去,跟isProFormComponent无关。
const { children: filedChildren, onChange, onBlur, ignoreFormItem, valuePropName = 'value', ...restProps } = formFieldProps;
omitUndefined({ ...restProps, [valuePropName]: formFieldProps[valuePropName], ...filedChildren.props, onChange: finalChange, fieldProps, })

就是restProps中没有onBlur了,所以没有透传给proformItem下的组件

@taajason
Copy link

taajason commented May 21, 2024

在使用 2.7 版本的时候,发现是可以的
当在rules中设置时,无法触发校验,如下:
<ProFormText rules={[ { required: true, validator: validatorFunc, validateTrigger: "onBlur" }, ]} />
当validateTrigger属性放在ProFormText中时,触发可以生效
<ProFormText validateTrigger="onBlur" rules={[ { required: true, validator: validatorFunc }, ]} />
官方文档中也是如此设置,希望有帮助!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants