Skip to content

Commit bdb5653

Browse files
fix: 🐛 修复 Form 表单 validator 校验不通过且未指定错误信息时无法显示校验信息的问题 (#791)
1 parent 44df081 commit bdb5653

File tree

1 file changed

+4
-7
lines changed
  • src/uni_modules/wot-design-uni/components/wd-form

1 file changed

+4
-7
lines changed

src/uni_modules/wot-design-uni/components/wd-form/wd-form.vue

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default {
1919
<script lang="ts" setup>
2020
import wdToast from '../wd-toast/wd-toast.vue'
2121
import { reactive, watch } from 'vue'
22-
import { deepClone, getPropByPath, isDef, isPromise } from '../common/util'
22+
import { deepClone, getPropByPath, isDef, isPromise, isString } from '../common/util'
2323
import { useChildren } from '../composables/useChildren'
2424
import { useToast } from '../wd-toast'
2525
import { type FormRules, FORM_KEY, type ErrorMessage, formProps, type FormExpose } from './types'
@@ -94,12 +94,9 @@ async function validate(prop?: string): Promise<{ valid: boolean; errors: ErrorM
9494
valid = false
9595
}
9696
})
97-
.catch((error: string | Error) => {
98-
const message = typeof error === 'string' ? error : error.message
99-
errors.push({
100-
prop,
101-
message: message || rule.message
102-
})
97+
.catch((error?: string | Error) => {
98+
const message = isDef(error) ? (isString(error) ? error : error.message || rule.message) : rule.message
99+
errors.push({ prop, message })
103100
valid = false
104101
})
105102
)

0 commit comments

Comments
 (0)