Skip to content

Commit f25409f

Browse files
feat: ✨ Form设置提示模式为toast时优先显示顺序靠前的表单项的错误提示
Closes: #548
1 parent 781355b commit f25409f

File tree

1 file changed

+12
-11
lines changed
  • src/uni_modules/wot-design-uni/components/wd-form

1 file changed

+12
-11
lines changed

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { useChildren } from '../composables/useChildren'
2323
import { useToast } from '../wd-toast'
2424
import { type FormRules, FORM_KEY, type ErrorMessage, formProps, type FormExpose } from './types'
2525
26-
const toast = useToast('wd-form-toast')
26+
const { show: showToast } = useToast('wd-form-toast')
2727
const props = defineProps(formProps)
2828
2929
const { children, linkChildren } = useChildren(FORM_KEY)
@@ -117,9 +117,7 @@ async function validate(prop?: string): Promise<{ valid: boolean; errors: ErrorM
117117
118118
await Promise.all(promises)
119119
120-
errors.forEach((error) => {
121-
showMessage(error)
122-
})
120+
showMessage(errors)
123121
124122
if (valid) {
125123
if (prop) {
@@ -150,13 +148,16 @@ function getMergeRules() {
150148
return mergedRules
151149
}
152150
153-
function showMessage(errorMsg: ErrorMessage) {
154-
if (!errorMsg.message) return
155-
156-
if (props.errorType === 'toast') {
157-
toast.show(errorMsg.message)
158-
} else if (props.errorType === 'message') {
159-
errorMessages[errorMsg.prop] = errorMsg.message
151+
function showMessage(errors: ErrorMessage[]) {
152+
const messages = errors.filter((error) => error.message)
153+
if (messages.length) {
154+
if (props.errorType === 'toast') {
155+
showToast(messages[0].message)
156+
} else if (props.errorType === 'message') {
157+
messages.forEach((error) => {
158+
errorMessages[error.prop] = error.message
159+
})
160+
}
160161
}
161162
}
162163

0 commit comments

Comments
 (0)