-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
form error feedback need support label instead of namepath #3255
Comments
Label 目前没法返回实际上是 async validator 的实现导致的,没有办法再进行封装从 ValidateError 中拿到 label,如果 async-validator 未来能增加一些相关的 feature,我倒是觉得把这个功能补上挺好的 |
这个我看过了,antd用的也是async validator,但是他的报错提示就是Label,他把报错结果处理了一下 const fillVariableResult = result.map(error => {
if (typeof error === 'string') {
return replaceMessage(error, kv);
}
return error;
}); /**
* Replace with template.
* `I'm ${name}` + { name: 'bamboo' } = I'm bamboo
*/
function replaceMessage(template: string, kv: Record<string, string>): string {
return template.replace(/\$\{\w+\}/g, (str: string) => {
const key = str.slice(2, -1);
return kv[key];
});
} |
没想到啊,居然自己人 hack 自己人 |
看起来只有 string 的情况下才 work,我当时应该是简单看过源码也考虑过类似的问题,就是处理不干净 |
This issue does not have any recent activity. If you are still experiencing similar problems, open a new error, including a minimal copy of the problem |
This function solves the problem (这个功能解决的问题)
当我使用多语言的时候,配置了:validate-messages="{ required: '请输入 %s' }",报错信息用户看到的报错信息是“请输入 user.name” ,使用 namepath 而不是label 会很疑惑。
Expected API (期望的 API)
希望支持报错信息用户看到的报错信息是“请输入 姓名”
https://codesandbox.io/s/hidden-monad-106ogf?file=/src/Demo.vue:338-381
The text was updated successfully, but these errors were encountered: