feat: add examples of asynchronous form verification and verification time (#4559)
* feat: add examples of asynchronous form verification and verification time
This commit is contained in:
@@ -175,6 +175,47 @@ const [Form, formApi] = useVbenForm({
|
||||
label: '密码',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入',
|
||||
},
|
||||
fieldName: 'input-blur',
|
||||
formFieldProps: {
|
||||
validateOnChange: false,
|
||||
validateOnModelUpdate: false,
|
||||
},
|
||||
help: 'blur时才会触发校验',
|
||||
label: 'blur触发',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入',
|
||||
},
|
||||
fieldName: 'input-async',
|
||||
label: '异步校验',
|
||||
rules: z
|
||||
.string()
|
||||
.min(3, '用户名至少需要3个字符')
|
||||
.refine(
|
||||
async (username) => {
|
||||
// 假设这是一个异步函数,模拟检查用户名是否已存在
|
||||
const checkUsernameExists = async (
|
||||
username: string,
|
||||
): Promise<boolean> => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
return username === 'existingUser';
|
||||
};
|
||||
const exists = await checkUsernameExists(username);
|
||||
return !exists;
|
||||
},
|
||||
{
|
||||
message: '用户名已存在',
|
||||
},
|
||||
),
|
||||
},
|
||||
],
|
||||
// 大屏一行显示3个,中屏一行显示2个,小屏一行显示1个
|
||||
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3',
|
||||
|
Reference in New Issue
Block a user