feat: Form 校验规则validator支持传入Error作为校验提示

 Closes: #667
This commit is contained in:
Moonofweisheng 2024-11-04 12:59:45 +08:00
parent 8c0e978314
commit db32ef9621
2 changed files with 5 additions and 4 deletions

View File

@ -149,7 +149,7 @@ const validator = (val: any) => {
if (String(val).length >= 4) {
return Promise.resolve()
} else {
return Promise.reject('长度不得小于4')
return Promise.reject(new Error('长度不得小于4'))
}
}

View File

@ -79,7 +79,7 @@ async function validate(prop?: string): Promise<{ valid: boolean; errors: ErrorM
if (isPromise(result)) {
promises.push(
result
.then((res: any) => {
.then((res) => {
if (typeof res === 'string') {
errors.push({
prop,
@ -94,10 +94,11 @@ async function validate(prop?: string): Promise<{ valid: boolean; errors: ErrorM
valid = false
}
})
.catch((error) => {
.catch((error: string | Error) => {
const message = typeof error === 'string' ? error : error.message
errors.push({
prop,
message: error || rule.message
message: message || rule.message
})
valid = false
})