primevue-mirror/apps/showcase/doc/forms/pt/PTViewer.vue

46 lines
1.4 KiB
Vue
Raw Normal View History

2024-10-23 04:05:27 +00:00
<template>
<DocPTViewer :docs="docs">
2024-10-23 07:27:06 +00:00
<Form v-slot="$form" :resolver="resolver" :initialValues="initialValues" @submit="onFormSubmit" class="flex flex-col gap-4 w-full sm:w-56">
<div class="flex flex-col gap-2">
<InputText name="username" type="text" placeholder="Username" fluid />
2024-10-23 11:59:52 +00:00
<Message v-if="$form.username?.invalid" severity="error">{{ $form.username.error.message }}</Message>
2024-10-23 07:27:06 +00:00
</div>
<Button type="submit" severity="secondary" label="Submit" />
</Form>
2024-10-23 04:05:27 +00:00
</DocPTViewer>
</template>
<script>
import { getPTOptions } from '@/components/doc/helpers';
2024-10-23 07:27:06 +00:00
import { zodResolver } from '@primevue/form/resolvers';
import { z } from 'zod';
2024-10-23 04:05:27 +00:00
export default {
data() {
return {
docs: [
{
2024-10-23 07:27:06 +00:00
data: getPTOptions('Form'),
key: 'Form'
2024-10-23 04:05:27 +00:00
}
2024-10-23 07:27:06 +00:00
],
initialValues: {
username: ''
},
resolver: zodResolver(
z.object({
username: z.string().min(1, { message: 'Username is required.' })
})
)
2024-10-23 04:05:27 +00:00
};
2024-10-23 07:27:06 +00:00
},
methods: {
onFormSubmit({ valid }) {
if (valid) {
this.$toast.add({ severity: 'success', summary: 'Form is submitted.', life: 3000 });
}
}
2024-10-23 04:05:27 +00:00
}
};
</script>