TreeSelect forms added
parent
17d638f809
commit
30204b5cd3
|
@ -0,0 +1,138 @@
|
|||
<template>
|
||||
<DocSectionText v-bind="$attrs">
|
||||
<p>TreeSelect is used with the <i>v-model</i> property.</p>
|
||||
</DocSectionText>
|
||||
<div class="card flex justify-center">
|
||||
<Form v-slot="$form" :resolver="resolver" :initialValues="initialValues" @submit="onFormSubmit" class="flex flex-col gap-4 w-full md:w-80">
|
||||
<div class="flex flex-col gap-2">
|
||||
<TreeSelect name="node" :options="nodes" placeholder="Select Item" fluid />
|
||||
<Message v-if="$form.node?.invalid" severity="error">{{ $form.node.errors[0]?.message }}</Message>
|
||||
</div>
|
||||
<Button type="submit" severity="secondary" label="Submit" />
|
||||
</Form>
|
||||
</div>
|
||||
<DocSectionCode :code="code" :dependencies="{ zod: '3.23.8' }" />
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { zodResolver } from '@primevue/form/resolvers';
|
||||
import { z } from 'zod';
|
||||
import { NodeService } from '/service/NodeService';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
initialValues: {
|
||||
node: null
|
||||
},
|
||||
resolver: zodResolver(
|
||||
z.object({
|
||||
node: z.union([z.record(z.boolean()), z.literal(null)]).refine((obj) => obj !== null && Object.keys(obj).length > 0, { message: 'TreeSelect is required.' })
|
||||
})
|
||||
),
|
||||
nodes: null,
|
||||
code: {
|
||||
basic: `
|
||||
<Form v-slot="$form" :resolver="resolver" :initialValues="initialValues" @submit="onFormSubmit" class="flex flex-col gap-4 w-full md:w-80">
|
||||
<div class="flex flex-col gap-2">
|
||||
<TreeSelect name="node" :options="nodes" placeholder="Select Item" fluid />
|
||||
<Message v-if="$form.node?.invalid" severity="error">{{ $form.node.errors[0]?.message }}</Message>
|
||||
</div>
|
||||
<Button type="submit" severity="secondary" label="Submit" />
|
||||
</Form>
|
||||
`,
|
||||
options: `
|
||||
<template>
|
||||
<div class="card flex justify-center">
|
||||
<Form v-slot="$form" :resolver="resolver" :initialValues="initialValues" @submit="onFormSubmit" class="flex flex-col gap-4 w-full md:w-80">
|
||||
<div class="flex flex-col gap-2">
|
||||
<TreeSelect name="node" :options="nodes" placeholder="Select Item" fluid />
|
||||
<Message v-if="$form.node?.invalid" severity="error">{{ $form.node.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';
|
||||
import { NodeService } from '/service/NodeService';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
initialValues: {
|
||||
node: null
|
||||
},
|
||||
resolver: zodResolver(
|
||||
z.object({
|
||||
node: z.union([z.record(z.boolean()), z.literal(null)]).refine((obj) => obj !== null && Object.keys(obj).length > 0, { message: 'TreeSelect is required.' })
|
||||
})
|
||||
),
|
||||
nodes: null,
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onFormSubmit({ valid }) {
|
||||
if (valid) {
|
||||
this.$toast.add({ severity: 'success', summary: 'Form is submitted.', life: 3000 });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
<\/script>
|
||||
|
||||
`,
|
||||
composition: `
|
||||
<template>
|
||||
<div class="card flex justify-center">
|
||||
<Form v-slot="$form" :resolver="resolver" :initialValues="initialValues" @submit="onFormSubmit" class="flex flex-col gap-4 w-full md:w-80">
|
||||
<div class="flex flex-col gap-2">
|
||||
<TreeSelect name="node" :options="nodes" placeholder="Select Item" fluid />
|
||||
<Message v-if="$form.node?.invalid" severity="error">{{ $form.node.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';
|
||||
import { NodeService } from '/service/NodeService';
|
||||
|
||||
const toast = useToast();
|
||||
const initialValues = ref({
|
||||
node: null
|
||||
});
|
||||
const resolver = ref(zodResolver(
|
||||
z.object({
|
||||
node: z.union([z.record(z.boolean()), z.literal(null)]).refine((obj) => obj !== null && Object.keys(obj).length > 0, { message: 'TreeSelect is required.' })
|
||||
})
|
||||
));
|
||||
|
||||
const onFormSubmit = ({ valid }) => {
|
||||
if (valid) {
|
||||
toast.add({ severity: 'success', summary: 'Form is submitted.', life: 3000 });
|
||||
}
|
||||
};
|
||||
<\/script>
|
||||
`
|
||||
}
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
NodeService.getTreeNodes().then((data) => (this.nodes = data));
|
||||
},
|
||||
methods: {
|
||||
onFormSubmit({ valid }) {
|
||||
if (valid) {
|
||||
this.$toast.add({ severity: 'success', summary: 'Form is submitted.', life: 3000 });
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
|
@ -18,6 +18,7 @@ import DisabledDoc from '@/doc/treeselect/DisabledDoc.vue';
|
|||
import FilledDoc from '@/doc/treeselect/FilledDoc.vue';
|
||||
import FilterDoc from '@/doc/treeselect/FilterDoc.vue';
|
||||
import FloatLabelDoc from '@/doc/treeselect/FloatLabelDoc.vue';
|
||||
import FormDoc from '@/doc/treeselect/FormDoc.vue';
|
||||
import IftaLabelDoc from '@/doc/treeselect/IftaLabelDoc.vue';
|
||||
import ImportDoc from '@/doc/treeselect/ImportDoc.vue';
|
||||
import InvalidDoc from '@/doc/treeselect/InvalidDoc.vue';
|
||||
|
@ -41,6 +42,11 @@ export default {
|
|||
label: 'Basic',
|
||||
component: BasicDoc
|
||||
},
|
||||
{
|
||||
id: 'form',
|
||||
label: 'Form',
|
||||
component: FormDoc
|
||||
},
|
||||
{
|
||||
id: 'multiple',
|
||||
label: 'Multiple',
|
||||
|
|
Loading…
Reference in New Issue