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

validator校验无法输出'${example}' #584

Open
jqy1012 opened this issue Apr 20, 2023 · 2 comments
Open

validator校验无法输出'${example}' #584

jqy1012 opened this issue Apr 20, 2023 · 2 comments

Comments

@jqy1012
Copy link

jqy1012 commented Apr 20, 2023

问题:在使用antd的Form.Item组件遇到,输入校验错误会输出undefined,问题代码如下:
<Form.Item
name={'demo'}
label={'demo'}
rules={[
{
validator: (rule, value) => {
if (!value) {
return Promise.reject('${example}');
}
return Promise.resolve();
},
},
]}

问题原因:查阅了代码发现validateUtil.ts这个文件的replaceMessage函数对'${}'字符串做了特殊处理,但是TS校验没有暴露出来这个处理。

解决:修改代码为如下,可以解决问题
<Form.Item
name={'demo'}
label={'demo'}
rules={[
{
validator: (rule, value) => {
if (!value) {
return Promise.reject('${example}');
}
return Promise.resolve();
},
example: '${example}',
},
]}

@fygethub
Copy link

+1

@yoyo837
Copy link
Member

yoyo837 commented Jul 11, 2024

辛苦带复现到antd开一个issue.

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