How do I make Nuxt UI update a ref whenever the UInput is changed? I tried using v-model and @input but it doesn't work. I'm showing the current value of the ref in a UCard
Expected behavior:
User types a value into the input
The value shown in the card updates
Actual behavior:
User types into input
Card does not update
Code:
import * as z from 'zod'
const modifyAnnouncementForm = z.object({
calendarEventId: z.union([z.number(), z.null()]),
});
type ModifyAnnouncementForm = z.output<typeof modifyAnnouncementForm>;
const modifyingAnnouncementFormState =
ref <
ModifyAnnouncementForm >
{
calendarEventId: null,
};
const openModifyModal = ref(false);
</script>
<template>
<UModal
v-model:open="openModifyModal"
:title="`Modifying "${modifyingAnnouncementFormState.title}"`"
:ui="{ footer: 'justify-end' }"
:close="{
color: 'error',
variant: 'subtle',
class: 'rounded-full',
}"
>
<template #body>
<UForm
:schema="modifyAnnouncementForm"
:state="modifyingAnnouncementFormState"
class="space-y-4"
>
<div class="calendarEvent">
<UFormField label="Calendar Event ID" name="calendarEventId">
<UInput
v-model="modifyingAnnouncementFormState.calendarEventId"
type="number"
@input="modifyingAnnouncementFormState.calendarEventId = (($event.target as HTMLInputElement).value as unknown as number)"
/>
</UFormField>
<UCard variant="subtle" class="calendarEventDetails">
<template #header>
<h1>{{ modifyingAnnouncementFormState.calendarEventId }}</h1>
</template>
</UCard>
</div>
<UButton type="submit"> Submit </UButton>
</UForm>
</template>
</UModal>
</template>