mirror of
https://github.com/keven1024/015.git
synced 2026-06-06 20:39:35 +00:00
feat(front): integrate VeeValidate for form validation and add InputField and FormButton components
This commit is contained in:
24
front/components/Field/FormButton.vue
Normal file
24
front/components/Field/FormButton.vue
Normal file
@@ -0,0 +1,24 @@
|
||||
<template>
|
||||
<Button @click="() => emit('click', form)" :disabled="!isValid">
|
||||
<slot />
|
||||
</Button>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { Button } from '~/components/ui/button'
|
||||
import { useFormContext } from 'vee-validate'
|
||||
const form = useFormContext()
|
||||
|
||||
const isValid = ref(false)
|
||||
watch(
|
||||
() => form?.values,
|
||||
async () => {
|
||||
const { valid } = await form?.validate()
|
||||
isValid.value = valid
|
||||
},
|
||||
{ deep: true }
|
||||
)
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'click', form: ReturnType<typeof useFormContext>): void
|
||||
}>()
|
||||
</script>
|
||||
16
front/components/Field/InputField.vue
Normal file
16
front/components/Field/InputField.vue
Normal file
@@ -0,0 +1,16 @@
|
||||
<template>
|
||||
<Field :name="props.name" v-slot="{ field }">
|
||||
<div class="flex flex-col gap-2">
|
||||
<Label v-if="props.label">{{ props.label }}</Label>
|
||||
<Input v-bind="field" :placeholder="props.placeholder" />
|
||||
</div>
|
||||
</Field>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { Input } from '~/components/ui/input'
|
||||
const props = defineProps<{
|
||||
name: string
|
||||
label?: string
|
||||
placeholder?: string
|
||||
}>()
|
||||
</script>
|
||||
Reference in New Issue
Block a user