InputText updates
parent
8c68ce77eb
commit
58c05c646d
|
@ -15,7 +15,7 @@
|
|||
<Button type="submit" severity="secondary" label="Submit" />
|
||||
</Form>
|
||||
</div>
|
||||
<DocSectionCode :code="code" />
|
||||
<DocSectionCode :code="code" :dependencies="{ zod: '3.23.8' }" />
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
@ -29,11 +29,12 @@ export default {
|
|||
username: '',
|
||||
email: ''
|
||||
},
|
||||
resolver: null,
|
||||
schema: z.object({
|
||||
username: z.string().min(1, { message: 'Username is required.' }),
|
||||
email: z.string().min(1, { message: 'Email is required.' }).email({ message: 'Email must be valid.' })
|
||||
}),
|
||||
resolver: zodResolver(
|
||||
z.object({
|
||||
username: z.string().min(1, { message: 'Username is required.' }),
|
||||
email: z.string().min(1, { message: 'Email is required.' }).email({ message: 'Email must be valid.' })
|
||||
})
|
||||
),
|
||||
code: {
|
||||
basic: `
|
||||
<Form v-slot="$form" :resolver="resolver" :initialValues="initialValues" @submit="onFormSubmit" class="flex justify-center flex-col gap-4">
|
||||
|
@ -45,21 +46,50 @@ export default {
|
|||
<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>
|
||||
<Button type="submit" severity="secondary" label="Submit" />
|
||||
</Form>
|
||||
`,
|
||||
options: `
|
||||
<template>
|
||||
<div class="card flex justify-center">
|
||||
<InputText type="text" v-model="value" />
|
||||
<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 />
|
||||
<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" fluid />
|
||||
<Message v-if="$form.email?.invalid" severity="error">{{ $form.email.errors[0]?.message }}</Message>
|
||||
</div>
|
||||
<Button type="submit" severity="secondary" label="Submit" />
|
||||
</Form>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { zodResolver } from '@primevue/form/resolvers';
|
||||
import { z } from 'zod';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
value: null
|
||||
initialValues: {
|
||||
username: '',
|
||||
email: ''
|
||||
},
|
||||
resolver: zodResolver(
|
||||
z.object({
|
||||
username: z.string().min(1, { message: 'Username is required.' }),
|
||||
email: z.string().min(1, { message: 'Email is required.' }).email({ message: 'Email must be valid.' })
|
||||
})
|
||||
)
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onFormSubmit({ valid }) {
|
||||
if (valid) {
|
||||
this.$toast.add({ severity: 'success', summary: 'Form is submitted.', life: 3000 });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -69,22 +99,48 @@ export default {
|
|||
composition: `
|
||||
<template>
|
||||
<div class="card flex justify-center">
|
||||
<InputText type="text" v-model="value" />
|
||||
<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 />
|
||||
<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" fluid />
|
||||
<Message v-if="$form.email?.invalid" severity="error">{{ $form.email.errors[0]?.message }}</Message>
|
||||
</div>
|
||||
<Button type="submit" severity="secondary" label="Submit" />
|
||||
</Form>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
import { zodResolver } from '@primevue/form/resolvers';
|
||||
import { useToast } from "primevue/usetoast";
|
||||
import { z } from 'zod';
|
||||
|
||||
const value = ref(null);
|
||||
const toast = useToast();
|
||||
const initialValues = ref({
|
||||
username: '',
|
||||
email: ''
|
||||
});
|
||||
const resolver = ref(zodResolver(
|
||||
z.object({
|
||||
username: z.string().min(1, { message: 'Username is required.' }),
|
||||
email: z.string().min(1, { message: 'Email is required.' }).email({ message: 'Email must be valid.' })
|
||||
})
|
||||
));
|
||||
|
||||
const onFormSubmit = ({ valid }) => {
|
||||
if (valid) {
|
||||
toast.add({ severity: 'success', summary: 'Form is submitted.', life: 3000 });
|
||||
}
|
||||
};
|
||||
<\/script>
|
||||
`
|
||||
}
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
this.resolver = zodResolver(this.schema);
|
||||
},
|
||||
methods: {
|
||||
onFormSubmit({ valid }) {
|
||||
if (valid) {
|
||||
|
|
Loading…
Reference in New Issue