2023-07-25 19:19:27 +02:00
|
|
|
<script setup lang="ts">
|
|
|
|
import { useForm } from 'vee-validate'
|
|
|
|
import { toTypedSchema } from '@vee-validate/yup'
|
|
|
|
import * as yup from 'yup'
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
schema: yup.ObjectShape
|
2023-07-26 04:08:17 +02:00
|
|
|
initialValues: Record<string, any>
|
2023-07-25 19:19:27 +02:00
|
|
|
}>()
|
|
|
|
|
|
|
|
const emit = defineEmits(['submit'])
|
|
|
|
|
|
|
|
const { handleSubmit } = useForm({
|
|
|
|
validationSchema: toTypedSchema(yup.object(props.schema)),
|
2023-07-26 04:08:17 +02:00
|
|
|
initialValues: props.initialValues,
|
2023-07-25 19:19:27 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
const onSubmit = handleSubmit((values) => {
|
|
|
|
emit('submit', values)
|
|
|
|
})
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<form novalidate @submit.prevent="onSubmit">
|
|
|
|
<slot name="default" />
|
|
|
|
</form>
|
|
|
|
</template>
|