FormItem 的验证可以扩展一下 远程验证逻辑吗?
https://baidu.github.io/amis/form/validation
最后一个是服务端验证
这个是提交表单的时候服务器返回验证错误,可不可以,onChange 的时候服务器验证呢?
如果你能传入 function,那么 form 那层有个 onValidate(values:{[propName:string] => any}) => void | string;
更正一下,是可以返回 promise 的。
onValidate(values:{[propName:string] => any}) => void |{[propName:string]: string | string[]} | Promise<void | {[propName:string]: string | string[]}>;
可以给我示例吗 ?
{
type: 'form',
controls: [
{
type: 'text',
name: 'a',
label: 'A'
}
],
onValdiate(values) {
if (values.a === '233') {
return {
a: 'A 不能是 233'
}
}
}
}
谢谢
onValdiate(values) {
// 在这里可以发异步请求吗?
}
{
type: 'form',
controls: [
{
type: 'text',
name: 'a',
label: 'A'
}
],
async onValdiate(values) {
const response = await axios(xxx);
if (values.a === '233') {
return {
a: 'A 不能是 233'
}
}
}
}
onValidate 可以返回一个 Promise<{[propName: string]: string | string[]}>
The last one is server-side validation
404 Page not found error