feat(Form): use nuxt useId to bind input labels (#1211)

This commit is contained in:
Romain Hamel
2024-01-31 18:22:02 +01:00
committed by GitHub
parent be37daec56
commit 27c71fa40e
5 changed files with 20 additions and 36 deletions

View File

@@ -5,6 +5,7 @@
</template>
<script lang="ts">
import { useId } from '#app'
import { provide, ref, type PropType, defineComponent, onUnmounted, onMounted } from 'vue'
import { useEventBus } from '@vueuse/core'
import type { ZodSchema } from 'zod'
@@ -12,7 +13,6 @@ import type { ValidationError as JoiError, Schema as JoiSchema } from 'joi'
import type { ObjectSchema as YupObjectSchema, ValidationError as YupError } from 'yup'
import type { ObjectSchemaAsync as ValibotObjectSchema } from 'valibot'
import type { FormError, FormEvent, FormEventType, FormSubmitEvent, FormErrorEvent, Form } from '../../types/form'
import { uid } from '../../utils/uid'
class FormException extends Error {
constructor (message: string) {
@@ -49,7 +49,8 @@ export default defineComponent({
},
emits: ['submit', 'error'],
setup (props, { expose, emit }) {
const bus = useEventBus<FormEvent>(`form-${uid()}`)
const formId = useId()
const bus = useEventBus<FormEvent>(`form-${formId}`)
onMounted(() => {
bus.on(async (event) => {