Merge branch 'v4.2.0-form' of https://github.com/primefaces/primevue into v4.2.0-form

pull/6632/head
Mert Sincan 2024-10-21 14:03:06 +01:00
commit 15cc6d915c
2 changed files with 102 additions and 0 deletions

View File

@ -0,0 +1,96 @@
<template>
<DocSectionText v-bind="$attrs">
<p>InputText is used with the <i>v-model</i> property.</p>
</DocSectionText>
<div class="card flex justify-center">
<Form v-slot="$form" :resolver="resolver" :defaultValues="defaultValues" @submit="onFormSubmit" class="flex justify-center flex-col gap-4">
<div class="flex flex-col gap-2">
<InputText name="username" type="text" placeholder="Username" />
<Message v-if="$form.username?.invalid" severity="error">{{ $form.username.errors[0]?.message }}</Message>
</div>
<div class="flex flex-col gap-2">
<InputText name="email" type="text" placeholder="Email" />
<Message v-if="$form.email?.invalid" severity="error">{{ $form.email.errors[0]?.message }}</Message>
</div>
<Button type="submit" severity="secondary" class="self-center p-2">Submit</Button>
</Form>
</div>
<DocSectionCode :code="code" />
</template>
<script>
import { zodResolver } from '@primevue/form/resolvers';
import { z } from 'zod';
export default {
data() {
return {
defaultValues: {
username: '',
email: ''
},
resolver: null,
schema: z.object({
username: z.string().min(1, { message: 'Please enter your username.' }),
email: z.string().min(1, { message: 'Please enter your email.' }).email({ message: 'Email must be valid.' })
}),
code: {
basic: `
<Form v-slot="$form" :resolver="resolver" :defaultValues="defaultValues" @submit="onFormSubmit" class="flex justify-center flex-col gap-4">
<div class="flex flex-col gap-2">
<InputText name="username" type="text" placeholder="Username" />
<Message v-if="$form.username?.invalid" severity="error">{{ $form.username.errors[0]?.message }}</Message>
</div>
<div class="flex flex-col gap-2">
<InputText name="email" type="text" placeholder="Email" />
<Message v-if="$form.email?.invalid" severity="error">{{ $form.email.errors[0]?.message }}</Message>
</div>
<Button type="submit" severity="secondary" class="self-center p-2">Submit</Button>
</Form>
`,
options: `
<template>
<div class="card flex justify-center">
<InputText type="text" v-model="value" />
</div>
</template>
<script>
export default {
data() {
return {
value: null
}
}
}
<\/script>
`,
composition: `
<template>
<div class="card flex justify-center">
<InputText type="text" v-model="value" />
</div>
</template>
<script setup>
import { ref } from 'vue';
const value = ref(null);
<\/script>
`
}
};
},
mounted() {
this.resolver = zodResolver(this.schema);
},
methods: {
onFormSubmit({ valid }) {
if (valid) {
this.$toast.add({ severity: 'success', summary: 'Form is submitted.', life: 3000 });
}
}
}
};
</script>

View File

@ -8,6 +8,7 @@ import BasicDoc from '@/doc/inputtext/BasicDoc.vue';
import DisabledDoc from '@/doc/inputtext/DisabledDoc.vue'; import DisabledDoc from '@/doc/inputtext/DisabledDoc.vue';
import FilledDoc from '@/doc/inputtext/FilledDoc.vue'; import FilledDoc from '@/doc/inputtext/FilledDoc.vue';
import FloatLabelDoc from '@/doc/inputtext/FloatLabelDoc.vue'; import FloatLabelDoc from '@/doc/inputtext/FloatLabelDoc.vue';
import FormDoc from '@/doc/inputtext/FormDoc.vue';
import HelpTextDoc from '@/doc/inputtext/HelpTextDoc.vue'; import HelpTextDoc from '@/doc/inputtext/HelpTextDoc.vue';
import IftaLabelDoc from '@/doc/inputtext/IftaLabelDoc.vue'; import IftaLabelDoc from '@/doc/inputtext/IftaLabelDoc.vue';
import ImportDoc from '@/doc/inputtext/ImportDoc.vue'; import ImportDoc from '@/doc/inputtext/ImportDoc.vue';
@ -30,6 +31,11 @@ export default {
label: 'Basic', label: 'Basic',
component: BasicDoc component: BasicDoc
}, },
{
id: 'form',
label: 'Form',
component: FormDoc
},
{ {
id: 'filled', id: 'filled',
label: 'Filled', label: 'Filled',