enhance: added error prompt in form

This commit is contained in:
0xJacky 2023-05-06 21:59:56 +08:00
parent f305701b30
commit 6bc6ceac19
No known key found for this signature in database
GPG key ID: B6E4A6E4A561BAF0
13 changed files with 123 additions and 68 deletions

View file

@ -0,0 +1,46 @@
<script setup lang="ts">
import {computed} from 'vue'
import {useGettext} from 'vue3-gettext'
const {$gettext} = useGettext()
export interface Props {
dataIndex?: string
label?: string
extra?: string
error?: any
}
const props = defineProps<Props>()
const tag = computed(() => {
return props.error?.[props.dataIndex] ?? ''
})
const valid_status = computed(() => {
if (!!tag.value) {
return 'error'
} else {
return 'success'
}
})
const help = computed(() => {
if (tag.value.indexOf('required') > -1) {
return () => $gettext('This field should not be empty')
}
return () => {
}
})
</script>
<template>
<a-form-item :label="label" :extra="extra" :validate-status="valid_status" :help="help?.()"
:required="tag.indexOf('required')>-1">
<slot/>
</a-form-item>
</template>
<style scoped lang="less">
</style>