mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-12 19:05:55 +02:00
enhance: added error prompt in form
This commit is contained in:
parent
f305701b30
commit
6bc6ceac19
13 changed files with 123 additions and 68 deletions
46
frontend/src/components/StdDataEntry/StdFormItem.vue
Normal file
46
frontend/src/components/StdDataEntry/StdFormItem.vue
Normal 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>
|
Loading…
Add table
Add a link
Reference in a new issue