@primevue/mcp 4.5.5 → 5.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +45 -21
- package/README.md +48 -250
- package/data/components.json +47269 -0
- package/data/llms/components/accordion.md +629 -0
- package/data/llms/components/animateonscroll.md +165 -0
- package/data/llms/components/autocomplete.md +995 -0
- package/data/llms/components/avatar.md +264 -0
- package/data/llms/components/badge.md +200 -0
- package/data/llms/components/blockui.md +99 -0
- package/data/llms/components/breadcrumb.md +269 -0
- package/data/llms/components/button.md +902 -0
- package/data/llms/components/card.md +209 -0
- package/data/llms/components/carousel.md +506 -0
- package/data/llms/components/cascadeselect.md +1207 -0
- package/data/llms/components/chart.md +1022 -0
- package/data/llms/components/checkbox.md +401 -0
- package/data/llms/components/chip.md +206 -0
- package/data/llms/components/colorpicker.md +213 -0
- package/data/llms/components/commandmenu.md +660 -0
- package/data/llms/components/compare.md +407 -0
- package/data/llms/components/confirmdialog.md +343 -0
- package/data/llms/components/confirmpopup.md +252 -0
- package/data/llms/components/contextmenu.md +522 -0
- package/data/llms/components/datatable.md +5266 -0
- package/data/llms/components/dataview.md +569 -0
- package/data/llms/components/datepicker.md +964 -0
- package/data/llms/components/deferredcontent.md +96 -0
- package/data/llms/components/dialog.md +702 -0
- package/data/llms/components/divider.md +152 -0
- package/data/llms/components/dock.md +488 -0
- package/data/llms/components/drawer.md +469 -0
- package/data/llms/components/dynamicdialog.md +214 -0
- package/data/llms/components/editor.md +205 -0
- package/data/llms/components/fieldset.md +253 -0
- package/data/llms/components/fileupload.md +459 -0
- package/data/llms/components/floatlabel.md +144 -0
- package/data/llms/components/fluid.md +104 -0
- package/data/llms/components/focustrap.md +59 -0
- package/data/llms/components/forms.md +344 -0
- package/data/llms/components/galleria.md +1119 -0
- package/data/llms/components/gallery.md +1003 -0
- package/data/llms/components/iconfield.md +283 -0
- package/data/llms/components/iftalabel.md +96 -0
- package/data/llms/components/image.md +179 -0
- package/data/llms/components/imagecompare.md +108 -0
- package/data/llms/components/inplace.md +183 -0
- package/data/llms/components/inputcolor.md +869 -0
- package/data/llms/components/inputgroup.md +419 -0
- package/data/llms/components/inputmask.md +345 -0
- package/data/llms/components/inputnumber.md +551 -0
- package/data/llms/components/inputotp.md +345 -0
- package/data/llms/components/inputpassword.md +738 -0
- package/data/llms/components/inputtags.md +432 -0
- package/data/llms/components/inputtext.md +569 -0
- package/data/llms/components/installation.md +1 -0
- package/data/llms/components/keyfilter.md +116 -0
- package/data/llms/components/knob.md +318 -0
- package/data/llms/components/label.md +151 -0
- package/data/llms/components/laravel.md +53 -0
- package/data/llms/components/listbox.md +636 -0
- package/data/llms/components/mask.md +203 -0
- package/data/llms/components/mcp.md +39 -0
- package/data/llms/components/megamenu.md +563 -0
- package/data/llms/components/menu.md +651 -0
- package/data/llms/components/menubar.md +446 -0
- package/data/llms/components/message.md +497 -0
- package/data/llms/components/metergroup.md +281 -0
- package/data/llms/components/multiselect.md +752 -0
- package/data/llms/components/orderlist.md +224 -0
- package/data/llms/components/organizationchart.md +418 -0
- package/data/llms/components/paginator.md +221 -0
- package/data/llms/components/panel.md +321 -0
- package/data/llms/components/panelmenu.md +703 -0
- package/data/llms/components/password.md +657 -0
- package/data/llms/components/picklist.md +286 -0
- package/data/llms/components/popover.md +145 -0
- package/data/llms/components/progressbar.md +242 -0
- package/data/llms/components/progressspinner.md +104 -0
- package/data/llms/components/radiobutton.md +427 -0
- package/data/llms/components/rating.md +312 -0
- package/data/llms/components/ripple.md +91 -0
- package/data/llms/components/scrollarea.md +700 -0
- package/data/llms/components/scrollpanel.md +131 -0
- package/data/llms/components/scrolltop.md +87 -0
- package/data/llms/components/select.md +1251 -0
- package/data/llms/components/selectbutton.md +268 -0
- package/data/llms/components/sidebar.md +2232 -0
- package/data/llms/components/skeleton.md +302 -0
- package/data/llms/components/slider.md +416 -0
- package/data/llms/components/speeddial.md +402 -0
- package/data/llms/components/splitbutton.md +840 -0
- package/data/llms/components/splitter.md +447 -0
- package/data/llms/components/stepper.md +551 -0
- package/data/llms/components/styleclass.md +226 -0
- package/data/llms/components/tabs.md +609 -0
- package/data/llms/components/tag.md +178 -0
- package/data/llms/components/terminal.md +123 -0
- package/data/llms/components/textarea.md +519 -0
- package/data/llms/components/tieredmenu.md +578 -0
- package/data/llms/components/timeline.md +494 -0
- package/data/llms/components/toast.md +472 -0
- package/data/llms/components/togglebutton.md +276 -0
- package/data/llms/components/toggleswitch.md +271 -0
- package/data/llms/components/toolbar.md +140 -0
- package/data/llms/components/tooltip.md +160 -0
- package/data/llms/components/tree.md +1076 -0
- package/data/llms/components/treeselect.md +660 -0
- package/data/llms/components/treetable.md +2493 -0
- package/data/llms/components/virtualscroller.md +265 -0
- package/data/llms/guides/autoimport.md +28 -0
- package/data/llms/guides/cdn.md +72 -0
- package/data/llms/guides/configuration.md +158 -0
- package/data/llms/guides/customicons.md +67 -0
- package/data/llms/guides/guides/accessibility.md +27 -0
- package/data/llms/guides/guides/animations.md +119 -0
- package/data/llms/guides/guides/rtl.md +7 -0
- package/data/llms/guides/icons.md +136 -0
- package/data/llms/guides/installation.md +3 -0
- package/data/llms/guides/laravel.md +66 -0
- package/data/llms/guides/llms.md +15 -0
- package/data/llms/guides/mcp.md +104 -0
- package/data/llms/guides/migration/v4.md +15 -0
- package/data/llms/guides/migration/v5.md +15 -0
- package/data/llms/guides/nuxt.md +141 -0
- package/data/llms/guides/passthrough.md +137 -0
- package/data/llms/guides/primeclt.md +43 -0
- package/data/llms/guides/tailwind.md +151 -0
- package/data/llms/guides/theming/styled.md +497 -0
- package/data/llms/guides/theming/unstyled.md +57 -0
- package/data/llms/guides/uikit.md +3 -0
- package/data/llms/guides/vite.md +90 -0
- package/data/llms/llms-full.txt +54465 -0
- package/data/llms/llms.txt +132 -0
- package/data/llms/pages/accessibility.md +27 -0
- package/data/llms/pages/animations.md +119 -0
- package/data/llms/pages/autoimport.md +28 -0
- package/data/llms/pages/cdn.md +72 -0
- package/data/llms/pages/configuration.md +158 -0
- package/data/llms/pages/contribution.md +31 -0
- package/data/llms/pages/customicons.md +67 -0
- package/data/llms/pages/designer.md +79 -0
- package/data/llms/pages/dynamicimports.md +7 -0
- package/data/llms/pages/forms.md +63 -0
- package/data/llms/pages/guides/accessibility.md +27 -0
- package/data/llms/pages/guides/animations.md +119 -0
- package/data/llms/pages/guides/rtl.md +7 -0
- package/data/llms/pages/icons.md +136 -0
- package/data/llms/pages/installation.md +3 -0
- package/data/llms/pages/introduction.md +23 -0
- package/data/llms/pages/laravel.md +66 -0
- package/data/llms/pages/llms.md +15 -0
- package/data/llms/pages/mcp.md +104 -0
- package/data/llms/pages/migration/v4.md +15 -0
- package/data/llms/pages/migration/v5.md +15 -0
- package/data/llms/pages/nuxt.md +141 -0
- package/data/llms/pages/passthrough.md +137 -0
- package/data/llms/pages/primeclt.md +43 -0
- package/data/llms/pages/rtl.md +7 -0
- package/data/llms/pages/setup.md +3 -0
- package/data/llms/pages/styled.md +497 -0
- package/data/llms/pages/tailwind.md +151 -0
- package/data/llms/pages/theming/styled.md +497 -0
- package/data/llms/pages/theming/unstyled.md +57 -0
- package/data/llms/pages/uikit.md +3 -0
- package/data/llms/pages/unstyled.md +57 -0
- package/data/llms/pages/v4.md +15 -0
- package/data/llms/pages/v5.md +15 -0
- package/data/llms/pages/vite.md +90 -0
- package/data/manifest.json +11117 -0
- package/data/mcp-data.json +55940 -0
- package/dist/index.d.ts +17 -1
- package/dist/index.js +66066 -72541
- package/package.json +10 -12
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# Fluid
|
|
2
|
+
|
|
3
|
+
Fluid is a layout component to make descendant components span full width of their container.
|
|
4
|
+
|
|
5
|
+
## Basic
|
|
6
|
+
|
|
7
|
+
Components with the fluid option like InputText have the ability to span the full width of their component. Enabling the fluid for each component individually may be cumbersome so wrap the content with Fluid instead for an easier alternative.
|
|
8
|
+
|
|
9
|
+
```vue
|
|
10
|
+
<template>
|
|
11
|
+
<div>
|
|
12
|
+
<Fluid>
|
|
13
|
+
<Label for="with-fluid" class="font-bold! mb-2 block">With Fluid</Label>
|
|
14
|
+
<InputText id="with-fluid" placeholder="Type..." />
|
|
15
|
+
</Fluid>
|
|
16
|
+
</div>
|
|
17
|
+
</template>
|
|
18
|
+
|
|
19
|
+
<script setup>
|
|
20
|
+
import Fluid from 'primevue/fluid';
|
|
21
|
+
import InputText from 'primevue/inputtext';
|
|
22
|
+
import Label from 'primevue/label';
|
|
23
|
+
<\/script>
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Comparison
|
|
27
|
+
|
|
28
|
+
The fluid property can be enabled per component, or applied to a group of components by wrapping them with Fluid . A child component's own fluid property takes precedence over the container, as shown in the last sample.
|
|
29
|
+
|
|
30
|
+
```vue
|
|
31
|
+
<template>
|
|
32
|
+
<div class="flex flex-col gap-6">
|
|
33
|
+
<div>
|
|
34
|
+
<Label for="non-fluid" class="font-bold! mb-2 block">Non-Fluid</Label>
|
|
35
|
+
<InputText id="non-fluid" />
|
|
36
|
+
</div>
|
|
37
|
+
|
|
38
|
+
<div>
|
|
39
|
+
<Label for="fluid" class="font-bold! mb-2 block">Fluid Prop</Label>
|
|
40
|
+
<InputText id="fluid" fluid />
|
|
41
|
+
</div>
|
|
42
|
+
|
|
43
|
+
<Fluid>
|
|
44
|
+
<span class="font-bold mb-2 block">Fluid Container</span>
|
|
45
|
+
<div class="grid grid-cols-2 gap-4">
|
|
46
|
+
<div>
|
|
47
|
+
<InputText />
|
|
48
|
+
</div>
|
|
49
|
+
<div>
|
|
50
|
+
<InputText />
|
|
51
|
+
</div>
|
|
52
|
+
<div class="col-span-full">
|
|
53
|
+
<InputText />
|
|
54
|
+
</div>
|
|
55
|
+
<div>
|
|
56
|
+
<InputText :fluid="false" placeholder="Non-Fluid" />
|
|
57
|
+
</div>
|
|
58
|
+
</div>
|
|
59
|
+
</Fluid>
|
|
60
|
+
</div>
|
|
61
|
+
</template>
|
|
62
|
+
|
|
63
|
+
<script setup>
|
|
64
|
+
import Fluid from 'primevue/fluid';
|
|
65
|
+
import InputText from 'primevue/inputtext';
|
|
66
|
+
import Label from 'primevue/label';
|
|
67
|
+
<\/script>
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Accessibility
|
|
71
|
+
|
|
72
|
+
Screen Reader Fluid does not require any roles and attributes. Keyboard Support Component does not include any interactive elements.
|
|
73
|
+
|
|
74
|
+
## Fluid API
|
|
75
|
+
|
|
76
|
+
### Props
|
|
77
|
+
|
|
78
|
+
| Name |Type |Default |Description |
|
|
79
|
+
| --- | --- | --- | --- |
|
|
80
|
+
| dt | any | - | It generates scoped CSS variables using design tokens for the component. |
|
|
81
|
+
| pt | PassThrough<FluidPassThroughOptions> | - | Used to pass attributes to DOM elements inside the component. |
|
|
82
|
+
| ptOptions | any | - | Used to configure passthrough(pt) options of the component. |
|
|
83
|
+
| unstyled | boolean | false | When enabled, it removes component related styles in the core. |
|
|
84
|
+
|
|
85
|
+
### Slots
|
|
86
|
+
|
|
87
|
+
| Name |Parameters |Description |
|
|
88
|
+
| --- | --- | --- |
|
|
89
|
+
| default | Function | |
|
|
90
|
+
|
|
91
|
+
### Pass Through Options
|
|
92
|
+
|
|
93
|
+
| Name |Type |Description |
|
|
94
|
+
| --- | --- | --- |
|
|
95
|
+
| root | FluidPassThroughOptionType | Used to pass attributes to the root's DOM element. |
|
|
96
|
+
| hooks | any | Used to manage all lifecycle hooks. |
|
|
97
|
+
|
|
98
|
+
### Theming
|
|
99
|
+
|
|
100
|
+
### CSS Classes
|
|
101
|
+
|
|
102
|
+
| Class |Description |
|
|
103
|
+
| --- | --- |
|
|
104
|
+
| p-fluid | Class name of the root element |
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Focus Trap
|
|
2
|
+
|
|
3
|
+
Focus Trap keeps focus within a certain DOM element while tabbing.
|
|
4
|
+
|
|
5
|
+
## Basic
|
|
6
|
+
|
|
7
|
+
FocusTrap is applied to a container element with the v-focustrap directive.
|
|
8
|
+
|
|
9
|
+
```vue
|
|
10
|
+
<template>
|
|
11
|
+
<div class="flex justify-center">
|
|
12
|
+
<div v-focustrap class="w-full sm:w-80 flex flex-col gap-5">
|
|
13
|
+
<IconField>
|
|
14
|
+
<InputIcon>
|
|
15
|
+
<User />
|
|
16
|
+
</InputIcon>
|
|
17
|
+
<InputText id="input" v-model="name" type="text" placeholder="Name" autofocus fluid />
|
|
18
|
+
</IconField>
|
|
19
|
+
|
|
20
|
+
<IconField>
|
|
21
|
+
<InputIcon>
|
|
22
|
+
<Envelope />
|
|
23
|
+
</InputIcon>
|
|
24
|
+
<InputText id="email" v-model="email" type="email" placeholder="Email" fluid />
|
|
25
|
+
</IconField>
|
|
26
|
+
|
|
27
|
+
<div class="flex items-center gap-2">
|
|
28
|
+
<Checkbox id="accept" v-model="accept" name="accept" value="Accept" />
|
|
29
|
+
<label for="accept" class="text-sm">I agree to the terms and conditions.</label>
|
|
30
|
+
</div>
|
|
31
|
+
|
|
32
|
+
<Button type="submit" class="mt-2 w-full">Submit</Button>
|
|
33
|
+
</div>
|
|
34
|
+
</div>
|
|
35
|
+
</template>
|
|
36
|
+
|
|
37
|
+
<script setup>
|
|
38
|
+
import { ref } from 'vue';
|
|
39
|
+
import Envelope from '@primeicons/vue/envelope';
|
|
40
|
+
import User from '@primeicons/vue/user';
|
|
41
|
+
|
|
42
|
+
const name = ref();
|
|
43
|
+
const email = ref();
|
|
44
|
+
const accept = ref(false);
|
|
45
|
+
<\/script>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Focus Trap API
|
|
49
|
+
|
|
50
|
+
### Pass Through Options
|
|
51
|
+
|
|
52
|
+
| Name |Type |Description |
|
|
53
|
+
| --- | --- | --- |
|
|
54
|
+
| root | FocusTrapDirectivePassThroughOptionType | Used to pass attributes to the root's DOM element. |
|
|
55
|
+
| firstFocusableElement | FocusTrapDirectivePassThroughOptionType | Used to pass attributes to the first focusable element's DOM element. |
|
|
56
|
+
| lastFocusableElement | FocusTrapDirectivePassThroughOptionType | Used to pass attributes to the last focusable element's DOM element. |
|
|
57
|
+
| hooks | any | Used to manage all lifecycle hooks. |
|
|
58
|
+
|
|
59
|
+
### Theming
|
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
# Forms
|
|
2
|
+
|
|
3
|
+
The PrimeVue Forms library provides comprehensive form state management with built-in validation support.
|
|
4
|
+
|
|
5
|
+
## Download
|
|
6
|
+
|
|
7
|
+
Forms add-on is available for download on the npm registry.
|
|
8
|
+
|
|
9
|
+
```vue
|
|
10
|
+
# Using npm
|
|
11
|
+
npm install @primevue/forms
|
|
12
|
+
|
|
13
|
+
# Using yarn
|
|
14
|
+
yarn add @primevue/forms
|
|
15
|
+
|
|
16
|
+
# Using pnpm
|
|
17
|
+
pnpm add @primevue/forms
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Import
|
|
21
|
+
|
|
22
|
+
The form component is responsible for managing the form state and must encapsulate the form fields.
|
|
23
|
+
|
|
24
|
+
```vue
|
|
25
|
+
import { Form } from '@primevue/forms';
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Basic
|
|
29
|
+
|
|
30
|
+
All PrimeVue form components are designed for seamless integration with the forms library. Instead of using the standard v-model , the name property is used to link a state object that tracks values, errors, and actions. The form component provides four key properties for state management.
|
|
31
|
+
|
|
32
|
+
```vue
|
|
33
|
+
<template>
|
|
34
|
+
<Form v-slot="$form" :initialValues :resolver @submit="onFormSubmit" class="flex flex-col gap-4 w-full sm:w-56">
|
|
35
|
+
<div class="flex flex-col gap-1">
|
|
36
|
+
<InputText name="username" type="text" placeholder="Username" fluid />
|
|
37
|
+
<Message v-if="$form.username?.invalid" severity="error" size="small" variant="simple">{{ $form.username.error?.message }}</Message>
|
|
38
|
+
</div>
|
|
39
|
+
<Button type="submit" severity="secondary">Submit</Button>
|
|
40
|
+
</Form>
|
|
41
|
+
</template>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## States
|
|
45
|
+
|
|
46
|
+
The $form object tracks the state management of the fields. Each field is linked with the name property. View the FormFieldState type in the API documentation for details about each property.
|
|
47
|
+
|
|
48
|
+
```vue
|
|
49
|
+
<template>
|
|
50
|
+
<Form v-slot="$form" :initialValues :resolver @submit="onFormSubmit" class="grid lg:grid-cols-2 gap-4 w-full">
|
|
51
|
+
<div class="flex flex-col justify-center items-center gap-4">
|
|
52
|
+
<InputText name="username" type="text" placeholder="Username" class="w-full sm:w-56" />
|
|
53
|
+
<Button type="submit" severity="secondary" class="w-full sm:w-56">Submit</Button>
|
|
54
|
+
</div>
|
|
55
|
+
<Fieldset legend="Form States" class="h-80 overflow-auto">
|
|
56
|
+
<pre class="whitespace-pre-wrap">{{ $form }}</pre>
|
|
57
|
+
</Fieldset>
|
|
58
|
+
</Form>
|
|
59
|
+
</template>
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Resolvers
|
|
63
|
+
|
|
64
|
+
Validations are implemented with the resolver property. A custom resolver is responsible for handling the validation and returning an errors object with key-value pairs where key is the form field name and value is an array of error object data. For productivity, we recommend using a schema validation library instead of building your own custom validation logic. The forms library provide built-in resolvers for popular options including Zod , Yup , Joi , Valibot , and Superstruct that can be imported from @primevue/forms/resolvers path.
|
|
65
|
+
|
|
66
|
+
```vue
|
|
67
|
+
<template>
|
|
68
|
+
<Form v-slot="$form" :initialValues :resolver="resolver" @submit="onFormSubmit" class="flex flex-col gap-4 w-full sm:w-56">
|
|
69
|
+
<div class="flex flex-col gap-1">
|
|
70
|
+
<InputText name="username" type="text" placeholder="Username" fluid />
|
|
71
|
+
<Message v-if="$form.username?.invalid" severity="error" size="small" variant="simple">{{ $form.username.error.message }}</Message>
|
|
72
|
+
</div>
|
|
73
|
+
<Button type="submit" severity="secondary">Submit</Button>
|
|
74
|
+
</Form>
|
|
75
|
+
</template>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## ValidateOn
|
|
79
|
+
|
|
80
|
+
Form component supports flexible validation triggers, allowing validation on value updates, blur events, form mount, or submission. These behaviors can be configured at form level or on specific fields via the validateOnValueUpdate , validateOnBlur , validateOnMount , and validateOnSubmit options of the formControl property. In this example, form disables validateOnValueUpdate and enables validateOnBlur at form level, and validates firstName on mount. The firstName field, overrides the form level setting locally.
|
|
81
|
+
|
|
82
|
+
```vue
|
|
83
|
+
<template>
|
|
84
|
+
<Form v-slot="$form" :initialValues :resolver :validateOnValueUpdate="false" :validateOnBlur="true" :validateOnMount="['firstName']" @submit="onFormSubmit" class="flex flex-col gap-4 w-full sm:w-56">
|
|
85
|
+
<div class="flex flex-col gap-1">
|
|
86
|
+
<InputText name="username" type="text" placeholder="Username" fluid />
|
|
87
|
+
<Message v-if="$form.username?.invalid" severity="error" size="small" variant="simple">{{ $form.username.error.message }}</Message>
|
|
88
|
+
</div>
|
|
89
|
+
<div class="flex flex-col gap-1">
|
|
90
|
+
<InputText name="firstName" type="text" placeholder="First Name" fluid :formControl="{ validateOnValueUpdate: true }" />
|
|
91
|
+
<Message v-if="$form.firstName?.invalid" severity="error" size="small" variant="simple">{{ $form.firstName.error.message }}</Message>
|
|
92
|
+
</div>
|
|
93
|
+
<div class="flex flex-col gap-1">
|
|
94
|
+
<InputText name="lastName" type="text" placeholder="Last Name" fluid />
|
|
95
|
+
<Message v-if="$form.lastName?.invalid" severity="error" size="small" variant="simple">{{ $form.lastName.error.message }}</Message>
|
|
96
|
+
</div>
|
|
97
|
+
<Button type="submit" severity="secondary">Submit</Button>
|
|
98
|
+
</Form>
|
|
99
|
+
</template>
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Import
|
|
103
|
+
|
|
104
|
+
The FormField is a helper component that provides validation and tracking for input elements, offering a more flexible structure to bind PrimeVue, non-PrimeVue components or native HTML elements to Form API. Additionally, with props like validateOn* , initialValue , resolver , and name , behaviors can be controlled directly from this component.
|
|
105
|
+
|
|
106
|
+
```vue
|
|
107
|
+
import { FormField } from '@primevue/forms';
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Built-in
|
|
111
|
+
|
|
112
|
+
Although PrimeVue components have built-in support for the Form API, you may still prefer to utilize the components as wrapped with the FormField. This is a matter of preference, for example in case you are also using FormField for other 3rd party components, your own custom components, and native elements, for consistency it may be an option.
|
|
113
|
+
|
|
114
|
+
```vue
|
|
115
|
+
<template>
|
|
116
|
+
<Form :resolver @submit="onFormSubmit" class="flex flex-col gap-4 w-full sm:w-56">
|
|
117
|
+
<FormField v-slot="$field" name="username" initialValue="" class="flex flex-col gap-1">
|
|
118
|
+
<InputText type="text" placeholder="Username" />
|
|
119
|
+
<Message v-if="$field?.invalid" severity="error" size="small" variant="simple">{{ $field.error?.message }}</Message>
|
|
120
|
+
</FormField>
|
|
121
|
+
<Button type="submit" severity="secondary">Submit</Button>
|
|
122
|
+
</Form>
|
|
123
|
+
</template>
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Non PrimeVue
|
|
127
|
+
|
|
128
|
+
Form API is not strictly tied to PrimeVue components, providing a flexible way to manage validation and state for any native HTML elements, your own custom components or third-party libraries.
|
|
129
|
+
|
|
130
|
+
```vue
|
|
131
|
+
<template>
|
|
132
|
+
<Form :resolver @submit="onFormSubmit" class="flex flex-col gap-4 w-full sm:w-56">
|
|
133
|
+
<FormField v-slot="$field" name="username" initialValue="" class="flex flex-col gap-1">
|
|
134
|
+
<input type="text" placeholder="Username" :class="[{ error: $field?.invalid }]" v-bind="$field.props" />
|
|
135
|
+
<Message v-if="$field?.invalid" severity="error" size="small" variant="simple">{{ $field.error?.message }}</Message>
|
|
136
|
+
</FormField>
|
|
137
|
+
<FormField v-slot="$field" name="password" initialValue="PrimeVue" class="flex flex-col gap-1">
|
|
138
|
+
<input v-model="$field.value" type="password" placeholder="Password" :class="[{ error: $field?.invalid }]" @input="$field.onInput" @blur="$field.onBlur" @change="$field.onChange" />
|
|
139
|
+
<Message v-if="$field?.invalid" severity="error" size="small" variant="simple">{{ $field.error?.message }}</Message>
|
|
140
|
+
</FormField>
|
|
141
|
+
<Button type="submit" severity="secondary">Submit</Button>
|
|
142
|
+
</Form>
|
|
143
|
+
</template>
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Resolver
|
|
147
|
+
|
|
148
|
+
Each FormField can have its own dedicated resolver, allowing you to define custom validation logic for individual fields. This flexibility enables tailored validation rules, ensuring that each form field meets specific criteria.
|
|
149
|
+
|
|
150
|
+
```vue
|
|
151
|
+
<template>
|
|
152
|
+
<Form :initialValues :resolver @submit="onFormSubmit" class="flex flex-col gap-4 w-full sm:w-80">
|
|
153
|
+
<FormField v-slot="$field" name="username" initialValue="" :resolver="zodUserNameResolver" class="flex flex-col gap-1">
|
|
154
|
+
<InputText type="text" placeholder="Username" />
|
|
155
|
+
<Message v-if="$field?.invalid" severity="error" size="small" variant="simple">{{ $field.error?.message }}</Message>
|
|
156
|
+
</FormField>
|
|
157
|
+
<FormField v-slot="$field" name="firstname" initialValue="" :resolver="yupFirstNameResolver" class="flex flex-col gap-1">
|
|
158
|
+
<InputText type="text" placeholder="First Name" />
|
|
159
|
+
<Message v-if="$field?.invalid" severity="error" size="small" variant="simple">{{ $field.error?.message }}</Message>
|
|
160
|
+
</FormField>
|
|
161
|
+
<FormField v-slot="$field" name="lastname" initialValue="" :resolver="valibotLastNameResolver" class="flex flex-col gap-1">
|
|
162
|
+
<InputText type="text" placeholder="Last Name" />
|
|
163
|
+
<Message v-if="$field?.invalid" severity="error" size="small" variant="simple">{{ $field.error?.message }}</Message>
|
|
164
|
+
</FormField>
|
|
165
|
+
<FormField v-slot="$field" name="password" initialValue="" :resolver="customPasswordResolver" class="flex flex-col gap-1">
|
|
166
|
+
<Password type="text" placeholder="Password" :feedback="false" toggleMask fluid />
|
|
167
|
+
<Message v-if="$field?.invalid" severity="error" size="small" variant="simple">{{ $field.error?.message }}</Message>
|
|
168
|
+
</FormField>
|
|
169
|
+
<FormField v-slot="$field" name="details" class="flex flex-col gap-1">
|
|
170
|
+
<Textarea placeholder="Details" />
|
|
171
|
+
<Message v-if="$field?.invalid" severity="error" size="small" variant="simple">{{ $field.error?.message }}</Message>
|
|
172
|
+
</FormField>
|
|
173
|
+
<Button type="submit" severity="secondary">Submit</Button>
|
|
174
|
+
</Form>
|
|
175
|
+
</template>
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Template
|
|
179
|
+
|
|
180
|
+
It renders as a HTML div element, but this behavior can be modified using the as and asChild props to render different HTML elements or to pass a custom component, allowing for greater flexibility in form structure.
|
|
181
|
+
|
|
182
|
+
```vue
|
|
183
|
+
<template>
|
|
184
|
+
<Form :resolver @submit="onFormSubmit" class="flex flex-col gap-4 w-full sm:w-56">
|
|
185
|
+
<FormField v-slot="$field" as="section" name="username" initialValue="" class="flex flex-col gap-2">
|
|
186
|
+
<InputText type="text" placeholder="Username" />
|
|
187
|
+
<Message v-if="$field?.invalid" severity="error" size="small" variant="simple">{{ $field.error?.message }}</Message>
|
|
188
|
+
</FormField>
|
|
189
|
+
<FormField v-slot="$field" asChild name="password" initialValue="">
|
|
190
|
+
<section class="flex flex-col gap-2">
|
|
191
|
+
<Password type="text" placeholder="Password" :feedback="false" toggleMask fluid />
|
|
192
|
+
<Message v-if="$field?.invalid" severity="error" size="small" variant="simple">{{ $field.error?.message }}</Message>
|
|
193
|
+
</section>
|
|
194
|
+
</FormField>
|
|
195
|
+
<Button type="submit" severity="secondary">Submit</Button>
|
|
196
|
+
</Form>
|
|
197
|
+
</template>
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Submit
|
|
201
|
+
|
|
202
|
+
The submit callback returns an object that encapsulates the form's validity, any existing errors, and its current state. This enables access to the form values, validation status, and any errors present at the time of submission. View the FormSubmitEvent in the API documentation for more information about the available event data.
|
|
203
|
+
|
|
204
|
+
```vue
|
|
205
|
+
<template>
|
|
206
|
+
<Form v-slot="$form" :initialValues :resolver @submit="onFormSubmit" class="flex flex-col gap-4 w-full sm:w-60">
|
|
207
|
+
<div class="flex flex-col gap-1">
|
|
208
|
+
<InputText name="username" type="text" placeholder="Username" fluid />
|
|
209
|
+
<Message v-if="$form.username?.invalid" severity="error" size="small" variant="simple">{{ $form.username.error.message }}</Message>
|
|
210
|
+
</div>
|
|
211
|
+
<div class="flex flex-col gap-1">
|
|
212
|
+
<Password name="password" placeholder="Password" :feedback="false" toggleMask fluid />
|
|
213
|
+
<Message v-if="$form.password?.invalid" severity="error" size="small" variant="simple">
|
|
214
|
+
<ul class="my-0 px-4 flex flex-col gap-1">
|
|
215
|
+
<li v-for="(error, index) of $form.password.errors" :key="index">{{ error.message }}</li>
|
|
216
|
+
</ul>
|
|
217
|
+
</Message>
|
|
218
|
+
</div>
|
|
219
|
+
<Button type="submit" severity="secondary">Submit</Button>
|
|
220
|
+
</Form>
|
|
221
|
+
</template>
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Dynamic
|
|
225
|
+
|
|
226
|
+
This section demonstrates how to create a dynamic form using a custom Form component. It showcases an example where form fields are generated dynamically based on the provided configuration, allowing for flexible form structures. The components named Dynamic* shown in this example are not built-in, and only available for sampling purposes. First form uses a declarative approach whereas second form goes for a programmatic approach. We suggest running this sample in StackBlitz to view the comprehensive implementation.
|
|
227
|
+
|
|
228
|
+
```vue
|
|
229
|
+
<template>
|
|
230
|
+
<Fieldset legend="Form 1" pt:content:class="flex justify-center">
|
|
231
|
+
<DynamicForm @submit="onFormSubmit('Form 1', $event)">
|
|
232
|
+
<DynamicFormField groupId="userId_1" name="username">
|
|
233
|
+
<DynamicFormLabel>Username</DynamicFormLabel>
|
|
234
|
+
<DynamicFormControl defaultValue="PrimeVue" fluid :schema="userNameSchema" />
|
|
235
|
+
<DynamicFormMessage />
|
|
236
|
+
</DynamicFormField>
|
|
237
|
+
<DynamicFormField groupId="passId_1" name="password">
|
|
238
|
+
<DynamicFormLabel>Password</DynamicFormLabel>
|
|
239
|
+
<DynamicFormControl as="Password" :feedback="false" toggleMask fluid :schema="passwordSchema" />
|
|
240
|
+
<DynamicFormMessage errorType="minimum" />
|
|
241
|
+
<DynamicFormMessage errorType="maximum" />
|
|
242
|
+
<DynamicFormMessage errorType="uppercase" severity="warn" />
|
|
243
|
+
<DynamicFormMessage errorType="lowercase" severity="warn" />
|
|
244
|
+
<DynamicFormMessage errorType="number" severity="secondary" />
|
|
245
|
+
</DynamicFormField>
|
|
246
|
+
<DynamicFormSubmit />
|
|
247
|
+
</DynamicForm>
|
|
248
|
+
</Fieldset>
|
|
249
|
+
|
|
250
|
+
<Fieldset legend="Form 2" pt:content:class="flex justify-center">
|
|
251
|
+
<DynamicForm :fields @submit="onFormSubmit('Form 2', $event)" />
|
|
252
|
+
</Fieldset>
|
|
253
|
+
</template>
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## Accessibility
|
|
257
|
+
|
|
258
|
+
Screen Reader Form does not require any roles and attributes. Keyboard Support Component does not include any interactive elements.
|
|
259
|
+
|
|
260
|
+
## Form API
|
|
261
|
+
|
|
262
|
+
### Props
|
|
263
|
+
|
|
264
|
+
| Name |Type |Default |Description |
|
|
265
|
+
| --- | --- | --- | --- |
|
|
266
|
+
| resolver | Function | - | |
|
|
267
|
+
| initialValues | Record<string, any> | - | The initial values for the form fields. |
|
|
268
|
+
| validateOnValueUpdate | boolean \| string[] | true | Whether to validate the form fields when the values change. |
|
|
269
|
+
| validateOnBlur | boolean \| string[] | false | Whether to validate the form fields when they lose focus (on blur). |
|
|
270
|
+
| validateOnMount | boolean \| string[] | false | Whether to validate the form fields immediately after the form is mounted. |
|
|
271
|
+
| validateOnSubmit | boolean \| string[] | true | Whether to validate the form fields when the form is submitted. |
|
|
272
|
+
| dt | any | - | It generates scoped CSS variables using design tokens for the component. |
|
|
273
|
+
| pt | PassThrough<FormPassThroughOptions> | - | Used to pass attributes to DOM elements inside the component. |
|
|
274
|
+
| ptOptions | PassThroughOptions | - | Used to configure passthrough(pt) options of the component. |
|
|
275
|
+
| unstyled | boolean | false | When enabled, it removes component related styles in the core. |
|
|
276
|
+
|
|
277
|
+
### Slots
|
|
278
|
+
|
|
279
|
+
| Name |Parameters |Description |
|
|
280
|
+
| --- | --- | --- |
|
|
281
|
+
| default | Function | |
|
|
282
|
+
|
|
283
|
+
### Emits
|
|
284
|
+
|
|
285
|
+
| Name |Parameters |Description |
|
|
286
|
+
| --- | --- | --- |
|
|
287
|
+
| submit | Function | |
|
|
288
|
+
| reset | Function | |
|
|
289
|
+
|
|
290
|
+
### Pass Through Options
|
|
291
|
+
|
|
292
|
+
| Name |Type |Description |
|
|
293
|
+
| --- | --- | --- |
|
|
294
|
+
| root | FormPassThroughOptionType | Used to pass attributes to the root's DOM element. |
|
|
295
|
+
| hooks | any | Used to manage all lifecycle hooks. |
|
|
296
|
+
|
|
297
|
+
### Theming
|
|
298
|
+
|
|
299
|
+
### CSS Classes
|
|
300
|
+
|
|
301
|
+
| Class |Description |
|
|
302
|
+
| --- | --- |
|
|
303
|
+
| p-form | The class of root element |
|
|
304
|
+
|
|
305
|
+
## Form Field API
|
|
306
|
+
|
|
307
|
+
### Props
|
|
308
|
+
|
|
309
|
+
| Name |Type |Default |Description |
|
|
310
|
+
| --- | --- | --- | --- |
|
|
311
|
+
| name | string | - | The name of the form field. |
|
|
312
|
+
| resolver | Function | - | |
|
|
313
|
+
| initialValue | any | - | The initial value for the form field. |
|
|
314
|
+
| validateOnValueUpdate | boolean | - | Whether to validate the form field when the value change. |
|
|
315
|
+
| validateOnBlur | boolean | - | Whether to validate the form field when it loses focus (on blur). |
|
|
316
|
+
| validateOnMount | boolean | - | Whether to validate the form field immediately after the form is mounted. |
|
|
317
|
+
| validateOnSubmit | boolean | - | Whether to validate the form field when the form is submitted. |
|
|
318
|
+
| as | string \| Component | DIV | Use to change the HTML tag of root element. |
|
|
319
|
+
| asChild | boolean | false | When enabled, it changes the default rendered element for the one passed as a child element. |
|
|
320
|
+
| dt | any | - | It generates scoped CSS variables using design tokens for the component. |
|
|
321
|
+
| pt | PassThrough<FormFieldPassThroughOptions> | - | Used to pass attributes to DOM elements inside the component. |
|
|
322
|
+
| ptOptions | PassThroughOptions | - | Used to configure passthrough(pt) options of the component. |
|
|
323
|
+
| unstyled | boolean | false | When enabled, it removes component related styles in the core. |
|
|
324
|
+
|
|
325
|
+
### Slots
|
|
326
|
+
|
|
327
|
+
| Name |Parameters |Description |
|
|
328
|
+
| --- | --- | --- |
|
|
329
|
+
| default | Function | |
|
|
330
|
+
|
|
331
|
+
### Pass Through Options
|
|
332
|
+
|
|
333
|
+
| Name |Type |Description |
|
|
334
|
+
| --- | --- | --- |
|
|
335
|
+
| root | FormFieldPassThroughOptionType | Used to pass attributes to the root's DOM element. |
|
|
336
|
+
| hooks | any | Used to manage all lifecycle hooks. |
|
|
337
|
+
|
|
338
|
+
### Theming
|
|
339
|
+
|
|
340
|
+
### CSS Classes
|
|
341
|
+
|
|
342
|
+
| Class |Description |
|
|
343
|
+
| --- | --- |
|
|
344
|
+
| p-formfield | The class of root element |
|