vlite3 1.5.11 → 1.5.13
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/README.md +20 -8
- package/components/Accordion/AccordionContent.vue.js +2 -2
- package/components/CategoryManager/CategoryManager2.vue.js +1 -1
- package/components/CommandPalette/CommandPaletteContent2.vue.js +1 -1
- package/components/CommandPalette/{CommandPaletteItem2.vue.js → CommandPaletteItem.vue.js} +1 -1
- package/components/Dropdown/DropdownMenu.vue.js +1 -1
- package/components/Form/{AccordionView.vue.js → AccordionView2.vue.js} +2 -2
- package/components/Form/Form.vue.js +2 -2
- package/components/Form/index2.vue.js +1 -1
- package/components/NavbarCommandPalette.vue.js +1 -1
- package/components/PanZoomViewport/PanZoomViewport.vue.d.ts +7 -7
- package/components/PanZoomViewport/PanZoomViewport.vue.js +1 -1
- package/components/Screen/ScreenFilter.vue.js +1 -1
- package/components/Splitter/Splitter.vue.d.ts +7 -0
- package/components/Splitter/Splitter.vue.js +33 -29
- package/components/Tabes/Tabes.vue.js +2 -2
- package/docs/README.md +17 -0
- package/docs/all-components.md +89 -0
- package/docs/component-index.md +313 -0
- package/docs/components/accordion.md +52 -0
- package/docs/components/alert.md +34 -0
- package/docs/components/app-shell.md +371 -0
- package/docs/components/async-select.md +264 -0
- package/docs/components/attachments-list.md +231 -0
- package/docs/components/avatar-group.md +74 -0
- package/docs/components/avatar-uploader.md +61 -0
- package/docs/components/avatar.md +28 -0
- package/docs/components/badge.md +81 -0
- package/docs/components/barcode.md +42 -0
- package/docs/components/beacon.md +29 -0
- package/docs/components/breadcrumb.md +317 -0
- package/docs/components/button-group.md +35 -0
- package/docs/components/button.md +86 -0
- package/docs/components/calendar.md +95 -0
- package/docs/components/carousel.md +122 -0
- package/docs/components/cart.md +533 -0
- package/docs/components/category-manager.md +269 -0
- package/docs/components/category-menu.md +251 -0
- package/docs/components/charts.md +1456 -0
- package/docs/components/chat.md +330 -0
- package/docs/components/checkbox.md +31 -0
- package/docs/components/chip.md +137 -0
- package/docs/components/choice-box.md +40 -0
- package/docs/components/clipboard.md +105 -0
- package/docs/components/clock.md +70 -0
- package/docs/components/color-picker.md +82 -0
- package/docs/components/command-palette.md +214 -0
- package/docs/components/comment-thread.md +171 -0
- package/docs/components/confirmation-modal.md +50 -0
- package/docs/components/custom-fields-display.md +94 -0
- package/docs/components/custom-fields.md +97 -0
- package/docs/components/data-list.md +93 -0
- package/docs/components/data-table.md +922 -0
- package/docs/components/date-picker.md +58 -0
- package/docs/components/date-range-picker.md +24 -0
- package/docs/components/date-time.md +104 -0
- package/docs/components/dropdown.md +740 -0
- package/docs/components/empty.md +100 -0
- package/docs/components/export-data.md +320 -0
- package/docs/components/file-picker.md +83 -0
- package/docs/components/file-preview.md +42 -0
- package/docs/components/file-tree.md +144 -0
- package/docs/components/footer.md +251 -0
- package/docs/components/forms.md +776 -0
- package/docs/components/gantt-chart.md +767 -0
- package/docs/components/google-login.md +67 -0
- package/docs/components/google-map.md +128 -0
- package/docs/components/heatmap.md +80 -0
- package/docs/components/icon-picker.md +58 -0
- package/docs/components/icon.md +176 -0
- package/docs/components/image-comparison.md +51 -0
- package/docs/components/image-magnifier.md +26 -0
- package/docs/components/import-data.md +521 -0
- package/docs/components/input.md +58 -0
- package/docs/components/invoice.md +339 -0
- package/docs/components/kanban.md +302 -0
- package/docs/components/label.md +25 -0
- package/docs/components/list.md +419 -0
- package/docs/components/masonry.md +55 -0
- package/docs/components/modal.md +133 -0
- package/docs/components/multi-select.md +54 -0
- package/docs/components/navbar.md +403 -0
- package/docs/components/number-input.md +41 -0
- package/docs/components/otp-input.md +68 -0
- package/docs/components/pagination.md +83 -0
- package/docs/components/pan-zoom-viewport.md +245 -0
- package/docs/components/permission-editor.md +322 -0
- package/docs/components/persona.md +56 -0
- package/docs/components/price.md +106 -0
- package/docs/components/pricing-plan.md +68 -0
- package/docs/components/progress-bar.md +53 -0
- package/docs/components/qr-code.md +59 -0
- package/docs/components/rating.md +59 -0
- package/docs/components/rich-text-editor.md +210 -0
- package/docs/components/scale-generator.md +101 -0
- package/docs/components/screen.md +208 -0
- package/docs/components/seo-provider.md +189 -0
- package/docs/components/side-panel.md +94 -0
- package/docs/components/sidebar-menu.md +422 -0
- package/docs/components/skeleton.md +115 -0
- package/docs/components/slider.md +48 -0
- package/docs/components/spinner.md +27 -0
- package/docs/components/splitter.md +97 -0
- package/docs/components/stats.md +234 -0
- package/docs/components/status-chip.md +232 -0
- package/docs/components/switch.md +23 -0
- package/docs/components/tabs.md +335 -0
- package/docs/components/tag-input.md +55 -0
- package/docs/components/textarea.md +31 -0
- package/docs/components/theme-provider.md +130 -0
- package/docs/components/theme-toggle.md +36 -0
- package/docs/components/thumbnail-selector.md +186 -0
- package/docs/components/timeline.md +225 -0
- package/docs/components/toast-notification.md +89 -0
- package/docs/components/tooltip.md +31 -0
- package/docs/components/workbook.md +102 -0
- package/docs/composables/use-theme.md +59 -0
- package/docs/getting-started/setup.md +176 -0
- package/docs/guides/draggable.md +211 -0
- package/docs/guides/internationalization.md +281 -0
- package/docs/guides/performance.md +118 -0
- package/docs/guides/testing-forms.md +154 -0
- package/docs/guides/testing-overlays.md +131 -0
- package/docs/guides/theming.md +124 -0
- package/docs/utilities/search.md +580 -0
- package/docs/utilities/utilities.md +371 -0
- package/docs-manifest.json +339 -0
- package/package.json +6 -15
- package/scripts/generate-docs-manifest.js +207 -0
- package/scripts/sync-docs.js +754 -0
- package/style.css +1 -1
- /package/components/Dropdown/{DropdownMenu2.vue.js → DropdownMenu3.vue.js} +0 -0
|
@@ -0,0 +1,776 @@
|
|
|
1
|
+
# Form
|
|
2
|
+
|
|
3
|
+
**Import:** `import { Form } from 'vlite3'`
|
|
4
|
+
|
|
5
|
+
### Description
|
|
6
|
+
|
|
7
|
+
A schema-driven form builder with built-in validation, multi-step wizards, grouped layouts, dynamic field dependencies, and automatic data mapping.
|
|
8
|
+
|
|
9
|
+
### Props
|
|
10
|
+
|
|
11
|
+
| Prop | Type | Default | Description |
|
|
12
|
+
| :------------------------- | :----------------------- | :--------------------------------------------------------------------- | :--------------------------------------------------------------------------- |
|
|
13
|
+
| `schema` | `IForm[] \| IForm[][]` | required | Array of field definitions (or array of arrays for grouped/multi-step) |
|
|
14
|
+
| `values` | `Record<string, any>` | `{}` | Initial form values |
|
|
15
|
+
| `variant` | `InputVariant` | global config or `'outline'` | Style variant for all inputs |
|
|
16
|
+
| `size` | `InputSize` | global config or `'md'` | Size of inputs |
|
|
17
|
+
| `rounded` | `InputRounded` | global config or `'md'` | Border radius of inputs |
|
|
18
|
+
| `class` | `string` | — | Custom class for the `<form>` element |
|
|
19
|
+
| `className` | `string` | — | Custom class passed to the inner grid layout |
|
|
20
|
+
| `loading` | `boolean` | `false` | Loading state on submit button |
|
|
21
|
+
| `schemaLoading` | `boolean` | `false` | Loading state for schema/initial data initialization |
|
|
22
|
+
| `columns` | `number \| string` | — | Grid columns (number or tailwind class) |
|
|
23
|
+
| `footer` | `boolean` | `true` | Show footer and submit button |
|
|
24
|
+
| `submitText` | `string` | `'Submit'` | Label for submit button |
|
|
25
|
+
| `submitProps` | `ButtonProps` | — | Extra props forwarded to submit button |
|
|
26
|
+
| `cancelText` | `string` | `'Cancel'` | Label for cancel button |
|
|
27
|
+
| `showCancel` | `boolean` | `false` | Show cancel button (auto-enabled when inside a Modal) |
|
|
28
|
+
| `isUpdate` | `boolean` | `false` | Mode for update/edit operations |
|
|
29
|
+
| `tabs` | `IFormStep[]` | — | Configuration for multi-step wizard |
|
|
30
|
+
| `groupsHeadings` | `string[] \| (ctx) => string[]` | — | Headings for grouped layout (static array or derived from form state) |
|
|
31
|
+
| `groupHeadingsDescription` | `string[] \| (ctx) => string[]` | — | Descriptions for grouped layout (static array or derived from form state) |
|
|
32
|
+
| `groupLayout` | `'basic' \| 'accordion'` | `'basic'` | Visual layout for grouped schemas (`schema: IForm[][]`) |
|
|
33
|
+
| `folderId` | `string` | — | Folder ID for file uploads |
|
|
34
|
+
| `groupClass` | `string` | — | Custom class for group items |
|
|
35
|
+
| `groupBodyClass` | `string` | — | Custom class for the group body area |
|
|
36
|
+
| `groupContainerClass` | `string` | — | Custom class for grouped layout containers |
|
|
37
|
+
| `headerClass` | `string` | — | Custom class for group/step headers |
|
|
38
|
+
| `footerClass` | `string` | — | Custom class for the footer area |
|
|
39
|
+
| `gridClass` | `string` | — | Custom class for the grid layout (overrides columns) |
|
|
40
|
+
| `timelineTextPosition` | `TimelineTextPosition` | `'right'` | Text position for timeline tabs in multi-step mode |
|
|
41
|
+
| `emitFields` | `string[]` | `['__typename']` | Fields to explicitly include in the submit payload (e.g. for GraphQL) |
|
|
42
|
+
| `showRequiredAsterisk` | `boolean` | global config or `true` | Show `*` indicator next to required field labels |
|
|
43
|
+
| `stickyFooter` | `boolean` | `false` | Pin the footer to the bottom of the viewport/container |
|
|
44
|
+
| `isPage` | `boolean` | `false` | Enable full-page layout mode (adds sticky header with back button and title) |
|
|
45
|
+
| `pageTitle` | `string` | — | Title shown in the page-mode header |
|
|
46
|
+
| `pageTitleI18n` | `string` | — | I18n key for the page-mode title |
|
|
47
|
+
| `pageTitleClass` | `string` | `'text-2xl font-bold'` | CSS class for the page-mode title element |
|
|
48
|
+
| `pageHeaderClass` | `string` | — | CSS class for the page-mode header container |
|
|
49
|
+
| `backButtonProps` | `ButtonProps` | `{ size: 'sm', variant: 'ghost', icon: 'heroicons-solid:arrow-left' }` | Props for the back button in page mode |
|
|
50
|
+
| `backButtonPath` | `string` | — | Fallback route path for the back button in page mode |
|
|
51
|
+
| `layout` | `'vertical' \| 'horizontal' \| 'inline'` | `'vertical'` | Layout of the form. Use `'inline'` to display fields and the submit button on the same line. |
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
> **Global Config:** `variant`, `size`, `rounded`, and `showRequiredAsterisk` resolve from the VLite global config (`vliteConfig.components.form`) when not explicitly passed as props.
|
|
55
|
+
|
|
56
|
+
> **Modal Integration:** When a Form is rendered inside a `Modal`, the cancel button is automatically shown, the footer becomes sticky, and the `close` method is automatically wired to the `@onSubmit` payload callback and the cancel button.
|
|
57
|
+
|
|
58
|
+
### Schema Interface (`IForm`)
|
|
59
|
+
|
|
60
|
+
| Property | Type | Description |
|
|
61
|
+
| :----------------- | :---------------------------------- | :---------------------------------------------------------------------------------- |
|
|
62
|
+
| `name` | `string` | Field key in values object (supports dot notation) |
|
|
63
|
+
| `label` | `string \| Component` | Display label (can be a string or a Vue component) |
|
|
64
|
+
| `labelI18n` | `string` | I18n translation key for the label (takes precedence over `label`) |
|
|
65
|
+
| `type` | `IFormFieldType \| (ctx) => any` | Input type (text, file, etc.) or a dynamic function returning a type |
|
|
66
|
+
| `value` | `any \| () => any` | Initial/default value for the field (can be a static value or factory function) |
|
|
67
|
+
| `placeholder` | `string` | Input placeholder text |
|
|
68
|
+
| `placeholderI18n` | `string` | I18n key for the placeholder (takes precedence over `placeholder`) |
|
|
69
|
+
| `required` | `boolean` | Marks field as required |
|
|
70
|
+
| `disabled` | `boolean \| (ctx) => boolean` | Disable field statically or conditionally |
|
|
71
|
+
| `readonly` | `boolean \| (ctx) => boolean` | Make field read-only statically or conditionally |
|
|
72
|
+
| `mapFrom` | `string` | Key to read the initial value from in the incoming `values` object |
|
|
73
|
+
| `mapTo` | `string` | Key to write the final value to in the submit payload |
|
|
74
|
+
| `valueKey` | `string` | Property to extract from nested objects or arrays of objects |
|
|
75
|
+
| `key` | `string` | Alias for `valueKey` |
|
|
76
|
+
| `format` | `(val, rawVals) => Promise\|any` | Format raw incoming data before it enters form state |
|
|
77
|
+
| `transform` | `(val, formVals) => Promise\|any` | Transform the form's state value before submission |
|
|
78
|
+
| `options` | `IDropdownOptions` | Options for select/multiSelect/radio fields |
|
|
79
|
+
| `validation` | `(ctx) => string \| Promise` | Custom validator — return an error message or empty string |
|
|
80
|
+
| `when` | `(ctx) => boolean` | Conditionally show/hide the field |
|
|
81
|
+
| `updateValues` | `(ctx) => Record \| Promise` | Dynamically update other fields when this field changes |
|
|
82
|
+
| `itemClass` | `string` | CSS class for the field wrapper (e.g. `col-span-2`) |
|
|
83
|
+
| `className` | `string` | CSS class applied to the input element itself |
|
|
84
|
+
| `icon` | `string` | Left icon (Iconify ID) |
|
|
85
|
+
| `iconRight` | `string` | Right icon (Iconify ID) |
|
|
86
|
+
| `addonLeft` | `string \| IFormAddon` | Left addon — plain text or addon config object |
|
|
87
|
+
| `addonRight` | `string \| IFormAddon` | Right addon — plain text or addon config object |
|
|
88
|
+
| `props` | `Record<string, any>` | Extra props forwarded to the field component (e.g., `addNewConfig` for `AsyncSelect`) |
|
|
89
|
+
| `min` | `number` | Minimum value for number inputs |
|
|
90
|
+
| `max` | `number` | Maximum value for number inputs |
|
|
91
|
+
| `maxFileSize` | `number` | Maximum file size in MB for file/avatar uploads |
|
|
92
|
+
| `maxFiles` | `number` | Maximum number of files allowed when `multiple` is true |
|
|
93
|
+
| `returnFileObject` | `boolean` | Output `{ fileName, fileUrl, fileType, fileSize }` on upload instead of a plain URL |
|
|
94
|
+
| `isSensitiveField` | `boolean` | Mark field as sensitive (e.g. for masking or audit logging) |
|
|
95
|
+
|
|
96
|
+
### Addon Interface (`IFormAddon`)
|
|
97
|
+
|
|
98
|
+
When `addonLeft` or `addonRight` is an object, it renders a dropdown or button inside the input addon. Each select addon binds to its own key in form state.
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
export interface IFormAddon {
|
|
102
|
+
/** Key in form values this addon writes to (required for select, optional for button) */
|
|
103
|
+
name?: string
|
|
104
|
+
/** 'select' renders a Dropdown; 'button' renders a Button */
|
|
105
|
+
type: 'select' | 'button'
|
|
106
|
+
/** Default value (for select addons) */
|
|
107
|
+
value?: any
|
|
108
|
+
/** Dropdown options (required when type='select') */
|
|
109
|
+
options?: IDropdownOptions
|
|
110
|
+
/** Button label (required when type='button') */
|
|
111
|
+
text?: string
|
|
112
|
+
/** Emitted action name on button click */
|
|
113
|
+
action?: string
|
|
114
|
+
/** Extra props forwarded to the rendered component */
|
|
115
|
+
props?: Record<string, any>
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Timeline Step Interface (`IFormStep`)
|
|
120
|
+
|
|
121
|
+
Configuration object for individual steps in a multi-step wizard. Passed as an array to the `tabs` prop.
|
|
122
|
+
|
|
123
|
+
| Property | Type | Description |
|
|
124
|
+
| :------------ | :------------------- | :---------------------------------------------------------- |
|
|
125
|
+
| `id` | `number \| string` | Unique identifier for the step |
|
|
126
|
+
| `title` | `string` | Display title for the step |
|
|
127
|
+
| `icon` | `string` | Optional Iconify ID for the step icon |
|
|
128
|
+
| `description` | `string` | Optional short description displayed underneath the title |
|
|
129
|
+
|
|
130
|
+
### Exposed (defineExpose)
|
|
131
|
+
|
|
132
|
+
The `Form` component exposes the following properties and methods via template ref:
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
defineExpose({
|
|
136
|
+
formValues,
|
|
137
|
+
errors,
|
|
138
|
+
isSubmitting,
|
|
139
|
+
handleSubmit,
|
|
140
|
+
validateAll,
|
|
141
|
+
resetForm,
|
|
142
|
+
setFieldError,
|
|
143
|
+
clearErrors,
|
|
144
|
+
setFieldValue: handleFieldChange,
|
|
145
|
+
})
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Events
|
|
149
|
+
|
|
150
|
+
- `@onSubmit` (payload: `{ values, isUpdate }`, close): Emitted when form is valid and submitted. The `close` function closes the parent Modal when applicable.
|
|
151
|
+
- `@onCancel`: Emitted when cancel button is clicked.
|
|
152
|
+
- `@onStepChange` (step: `number`): Emitted when step changes in multi-step mode.
|
|
153
|
+
- `@onAddonAction` (action: `string`): Emitted when a button addon is clicked (carries the `action` string from the addon config).
|
|
154
|
+
- `@onBack`: Emitted when the back button in page mode is clicked.
|
|
155
|
+
- `@onChange` (values: `Record<string, any>`): Emitted on every user-initiated field change. Payload is the full updated form values object.
|
|
156
|
+
|
|
157
|
+
### Slots
|
|
158
|
+
|
|
159
|
+
| Slot | Scope | Description |
|
|
160
|
+
| :--------------- | :----------------------------------------------- | :--------------------------------------------------------------------------------- |
|
|
161
|
+
| `default` | `{ values, errors, isSubmitting, handleSubmit }` | Append custom content after the generated form fields |
|
|
162
|
+
| `header-actions` | `{ values, isSubmitting, handleSubmit }` | Custom action buttons in the page-mode header (only visible when `isPage` is true) |
|
|
163
|
+
|
|
164
|
+
### Usage
|
|
165
|
+
|
|
166
|
+
#### Basic Form
|
|
167
|
+
|
|
168
|
+
```vue
|
|
169
|
+
<script setup>
|
|
170
|
+
const schema = [
|
|
171
|
+
{ name: 'email', label: 'Email', type: 'email', required: true },
|
|
172
|
+
{ name: 'password', label: 'Password', type: 'password', required: true },
|
|
173
|
+
]
|
|
174
|
+
</script>
|
|
175
|
+
|
|
176
|
+
<template>
|
|
177
|
+
<Form :schema="schema" @onSubmit="handleSubmit" />
|
|
178
|
+
</template>
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
#### Validation & Conditional Logic
|
|
182
|
+
|
|
183
|
+
```javascript
|
|
184
|
+
const schema = [
|
|
185
|
+
{
|
|
186
|
+
name: 'role',
|
|
187
|
+
label: 'Role',
|
|
188
|
+
type: 'select',
|
|
189
|
+
options: [
|
|
190
|
+
{ label: 'Admin', value: 'admin' },
|
|
191
|
+
{ label: 'User', value: 'user' },
|
|
192
|
+
],
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
name: 'adminCode',
|
|
196
|
+
label: 'Admin Code',
|
|
197
|
+
type: 'password',
|
|
198
|
+
// Only show if role is admin
|
|
199
|
+
when: ({ values }) => values.role === 'admin',
|
|
200
|
+
// Custom validation
|
|
201
|
+
validation: async ({ value }) => {
|
|
202
|
+
if (value !== 'SECRET') return 'Invalid code'
|
|
203
|
+
// Example Async validation
|
|
204
|
+
// const res = await verifyCodeAsync(value)
|
|
205
|
+
return ''
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
]
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
> **Note on Conditional Visibility:** Fields hidden via the `when` condition are strictly ignored by the form initialization and submission logic. Their default `value` will not pollute the form state, and they are automatically excluded from the final submission payload. This allows you to safely use the exact same `name` for multiple mutually-exclusive fields in your schema.
|
|
212
|
+
|
|
213
|
+
#### Dynamic Component Types
|
|
214
|
+
|
|
215
|
+
You can evaluate the `type` property dynamically based on the form's current state. This allows a single field to morph its UI representation without needing to duplicate fields or deal with complex state cleanup.
|
|
216
|
+
|
|
217
|
+
```javascript
|
|
218
|
+
const schema = [
|
|
219
|
+
{
|
|
220
|
+
name: 'cycle',
|
|
221
|
+
label: 'Pay Cycle',
|
|
222
|
+
type: 'select',
|
|
223
|
+
options: [
|
|
224
|
+
{ label: 'Weekly', value: 'weekly' },
|
|
225
|
+
{ label: 'Monthly', value: 'monthly' },
|
|
226
|
+
],
|
|
227
|
+
value: 'weekly'
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
name: 'range',
|
|
231
|
+
label: 'Select Period',
|
|
232
|
+
// Dynamically render a single date picker or a date range picker
|
|
233
|
+
type: ({ values }) => values.cycle === 'weekly' ? 'date' : 'dateRangePicker',
|
|
234
|
+
required: true,
|
|
235
|
+
}
|
|
236
|
+
]
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
#### Data Mapping & Formatting
|
|
240
|
+
|
|
241
|
+
The Form component can automatically extract, format, and transform complex API data structures so you don't have to write boilerplate mapping code. Both `format` and `transform` now seamlessly support `async` promises.
|
|
242
|
+
|
|
243
|
+
```javascript
|
|
244
|
+
// Example API Response:
|
|
245
|
+
// {
|
|
246
|
+
// id: 'prod_123',
|
|
247
|
+
// taxes: [{ id: 'tax_1', rate: 20 }, { id: 'tax_2', rate: 5 }],
|
|
248
|
+
// inventory_sizes: [{ sizeId: 'sz_m', qty: "10" }]
|
|
249
|
+
// }
|
|
250
|
+
|
|
251
|
+
const schema = [
|
|
252
|
+
{
|
|
253
|
+
name: 'taxIds', // Internal form state name
|
|
254
|
+
mapFrom: 'taxes', // Read from 'taxes' array in the incoming data
|
|
255
|
+
valueKey: 'id', // Automatically extract just the 'id' property from each object
|
|
256
|
+
type: 'multiSelect',
|
|
257
|
+
options: [
|
|
258
|
+
{ label: 'VAT', value: 'tax_1' },
|
|
259
|
+
{ label: 'Sales Tax', value: 'tax_2' },
|
|
260
|
+
],
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
name: 'sizes', // Internal form state name
|
|
264
|
+
mapFrom: 'inventory_sizes', // Read from 'inventory_sizes' in incoming data
|
|
265
|
+
mapTo: 'inventory_sizes', // Write back to 'inventory_sizes' in the submit payload
|
|
266
|
+
type: 'customFields',
|
|
267
|
+
// Transform data before submission (e.g., ensure quantities are Numbers)
|
|
268
|
+
transform: async (val) => val.map((s) => ({ ...s, qty: Number(s.qty) })),
|
|
269
|
+
props: {
|
|
270
|
+
schema: [
|
|
271
|
+
{ name: 'sizeId', type: 'select' /* options... */ },
|
|
272
|
+
{ name: 'qty', type: 'number' },
|
|
273
|
+
],
|
|
274
|
+
},
|
|
275
|
+
},
|
|
276
|
+
]
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
#### Multi-Step Wizard
|
|
280
|
+
|
|
281
|
+
```vue
|
|
282
|
+
<script setup>
|
|
283
|
+
const tabs = [
|
|
284
|
+
{ id: 1, title: 'Account', icon: 'lucide:user' },
|
|
285
|
+
{ id: 2, title: 'Profile', icon: 'lucide:settings' },
|
|
286
|
+
]
|
|
287
|
+
|
|
288
|
+
// Schema is array of arrays — one sub-array per step
|
|
289
|
+
const schema = [
|
|
290
|
+
[
|
|
291
|
+
// Step 1
|
|
292
|
+
{ name: 'username', label: 'Username', type: 'text' },
|
|
293
|
+
],
|
|
294
|
+
[
|
|
295
|
+
// Step 2
|
|
296
|
+
{ name: 'bio', label: 'Bio', type: 'textarea' },
|
|
297
|
+
],
|
|
298
|
+
]
|
|
299
|
+
</script>
|
|
300
|
+
|
|
301
|
+
<template>
|
|
302
|
+
<Form :tabs="tabs" :schema="schema" @onSubmit="console.log" />
|
|
303
|
+
</template>
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
#### Custom Fields (Repeater)
|
|
307
|
+
|
|
308
|
+
Use `type: 'customFields'` to create array/repeater fields.
|
|
309
|
+
|
|
310
|
+
Nested `when`, `disabled`, `readonly`, `validation`, and `updateValues` callbacks receive the
|
|
311
|
+
current row as `values` and the complete form state as `globalValues`. Validation errors block
|
|
312
|
+
submission. The compact table layout keeps row cells clean and displays one summary error below
|
|
313
|
+
the repeater; the accordion layout displays errors below the affected field. When any row is
|
|
314
|
+
invalid, the parent `customFields` field receives the summary error.
|
|
315
|
+
|
|
316
|
+
**Responsive table layout:** When `layout` is `'table'` (the default), viewports below the
|
|
317
|
+
Tailwind `md` breakpoint (768px) automatically switch from the multi-column grid to stacked
|
|
318
|
+
cards. Each row becomes a card with a toolbar (drag handle, row number, **smart row title**,
|
|
319
|
+
remove) and vertically stacked fields labeled from `headers` / schema labels. At `md` and
|
|
320
|
+
above, the original table grid is unchanged. Accordion layout is unchanged at all breakpoints.
|
|
321
|
+
|
|
322
|
+
**Row titles (accordion + stacked mobile):** Set `props.rowTitleKey` (e.g. `'label'` or
|
|
323
|
+
`'title'`) to pick the heading from each row. If omitted, CustomFields resolves a title from
|
|
324
|
+
`label` → `title` → `name`, then the first filled text/select field (including object
|
|
325
|
+
`{ label }` payloads). When nothing resolves, stacked cards fall back to `#1`, `#2`, … so the
|
|
326
|
+
header never looks empty. Legacy `accordionTitleKey` still works as an alias.
|
|
327
|
+
|
|
328
|
+
```javascript
|
|
329
|
+
const schema = [
|
|
330
|
+
{
|
|
331
|
+
name: 'teamMembers',
|
|
332
|
+
label: 'Team Members',
|
|
333
|
+
type: 'customFields',
|
|
334
|
+
props: {
|
|
335
|
+
draggable: true, // Enable drag and drop reordering
|
|
336
|
+
headers: ['Name', 'Role'],
|
|
337
|
+
schema: [
|
|
338
|
+
{ name: 'name', label: 'Name', type: 'text' },
|
|
339
|
+
{
|
|
340
|
+
name: 'role',
|
|
341
|
+
label: 'Role',
|
|
342
|
+
type: 'select',
|
|
343
|
+
options: [
|
|
344
|
+
{ label: 'Dev', value: 'dev' },
|
|
345
|
+
{ label: 'Design', value: 'design' },
|
|
346
|
+
],
|
|
347
|
+
},
|
|
348
|
+
],
|
|
349
|
+
},
|
|
350
|
+
},
|
|
351
|
+
]
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
#### File Uploads
|
|
355
|
+
|
|
356
|
+
Support for single file, multiple files, size limits, file count limits, different UI variants, and multi-image thumbnail selection. All of these field types use the global `services.upload` handler configured in `createVLite` — base64 / pending files are resolved to URLs before `onSubmit` fires.
|
|
357
|
+
|
|
358
|
+
```javascript
|
|
359
|
+
const schema = [
|
|
360
|
+
{
|
|
361
|
+
name: 'avatar',
|
|
362
|
+
label: 'Avatar',
|
|
363
|
+
type: 'avatarUpload', // Specialized avatar uploader — see AvatarUploader.md
|
|
364
|
+
maxFileSize: 5, // Maximum file size of 5MB
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
name: 'media',
|
|
368
|
+
label: 'Product Images',
|
|
369
|
+
type: 'thumbnailSelector', // Multi-image gallery + primary thumbnail — see ThumbnailSelector.md
|
|
370
|
+
maxFileSize: 5, // Maximum file size of 5MB per image
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
name: 'resume',
|
|
374
|
+
label: 'Resume',
|
|
375
|
+
type: 'fileUploader', // Dropzone style
|
|
376
|
+
props: { accept: '.pdf', allowRename: true },
|
|
377
|
+
maxFileSize: 10, // Maximum file size of 10MB
|
|
378
|
+
returnFileObject: true, // Output { fileName, fileUrl, fileType, fileSize } instead of just URL
|
|
379
|
+
},
|
|
380
|
+
{
|
|
381
|
+
name: 'documents',
|
|
382
|
+
label: 'Documents',
|
|
383
|
+
type: 'file', // Standard input style
|
|
384
|
+
props: { multiple: true },
|
|
385
|
+
maxFiles: 5, // Limit to a maximum of 5 files
|
|
386
|
+
maxFileSize: 2, // Maximum 2MB per file
|
|
387
|
+
},
|
|
388
|
+
]
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
##### Thumbnail selector (`type: 'thumbnailSelector'`)
|
|
392
|
+
|
|
393
|
+
Use this when a field needs a gallery of images plus one designated primary thumbnail (typical for products).
|
|
394
|
+
|
|
395
|
+
- **Form value shape:** `{ images: string[], thumbnail: string | null }`
|
|
396
|
+
- **Schema props:** `maxFileSize` (MB) maps to the component’s `maxSize`; `label`, `disabled`, and `when` work like any other field
|
|
397
|
+
- **Layout:** In non-multi-step forms, Form automatically places the field in a side panel (right on desktop, above fields on mobile). In multi-step wizards it renders inline
|
|
398
|
+
- **Uploads:** Pending `data:` URIs in `images[]` are uploaded via the global upload service; `thumbnail` is rewritten to the resolved URL in the same pass
|
|
399
|
+
|
|
400
|
+
```javascript
|
|
401
|
+
const schema = [
|
|
402
|
+
{ name: 'title', type: 'text', label: 'Product Title', required: true },
|
|
403
|
+
{
|
|
404
|
+
name: 'media',
|
|
405
|
+
type: 'thumbnailSelector',
|
|
406
|
+
label: 'Product Images',
|
|
407
|
+
maxFileSize: 5,
|
|
408
|
+
},
|
|
409
|
+
]
|
|
410
|
+
|
|
411
|
+
// On submit:
|
|
412
|
+
// values.media = {
|
|
413
|
+
// images: ['https://cdn.example.com/img1.jpg', 'https://cdn.example.com/img2.jpg'],
|
|
414
|
+
// thumbnail: 'https://cdn.example.com/img1.jpg',
|
|
415
|
+
// }
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
See [ThumbnailSelector](../advanced/thumbnail-selector.md) for standalone usage, accepted MIME types, and drag-to-reorder behavior.
|
|
419
|
+
|
|
420
|
+
#### Rich Text Editor
|
|
421
|
+
|
|
422
|
+
Use `type: 'richTextEditor'` to render a full WYSIWYG editor (bold/italic, lists, links, images, code). The field value is an HTML string. Images pasted or dropped into the editor are automatically uploaded through the form's file upload service — by the time the form submits, all `<img>` `src` attributes are resolved URLs.
|
|
423
|
+
|
|
424
|
+
```javascript
|
|
425
|
+
const schema = [
|
|
426
|
+
{
|
|
427
|
+
name: 'description',
|
|
428
|
+
label: 'Description',
|
|
429
|
+
type: 'richTextEditor',
|
|
430
|
+
required: true,
|
|
431
|
+
placeholder: 'Write a detailed description…',
|
|
432
|
+
props: {
|
|
433
|
+
minHeight: '240px', // optional — editor's min height
|
|
434
|
+
maxHeight: '480px', // optional — editor's max height (adds scroll)
|
|
435
|
+
// Restrict the toolbar to a curated subset — see "Toolbar customization" below.
|
|
436
|
+
tools: 'basic',
|
|
437
|
+
},
|
|
438
|
+
},
|
|
439
|
+
{
|
|
440
|
+
name: 'notes',
|
|
441
|
+
label: 'Internal Notes',
|
|
442
|
+
type: 'richTextEditor',
|
|
443
|
+
// Use `when` to toggle the field conditionally
|
|
444
|
+
when: ({ values }) => values.includeNotes === true,
|
|
445
|
+
},
|
|
446
|
+
]
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
> **Required validation:** The editor's empty state is HTML markup (e.g. `<p><br></p>`), not an empty string. The form's `required` check automatically strips HTML tags and treats the field as blank only when there is no visible text, so `required: true` works out of the box without a custom validator.
|
|
450
|
+
>
|
|
451
|
+
> **Image uploads:** Inline images go through `useFileUpload`, the same service used by `fileUploader` / `avatarUpload` / `thumbnailSelector`. If the form has a `folderId` prop, uploaded images are stored under that folder. There is no extra schema wiring — the editor handles it internally.
|
|
452
|
+
|
|
453
|
+
##### Toolbar customization
|
|
454
|
+
|
|
455
|
+
Restrict which formatting buttons appear in the editor's toolbar via `props.tools`. Accepts a curated preset, an array of tool IDs, or `undefined` (full default toolbar).
|
|
456
|
+
|
|
457
|
+
```javascript
|
|
458
|
+
// 1. Curated preset (string)
|
|
459
|
+
props: { tools: 'minimal' } // bold, italic, bullet list, link
|
|
460
|
+
props: { tools: 'basic' } // headings + inline + lists + image + link + clear
|
|
461
|
+
props: { tools: 'standard' } // everything except alignment buttons
|
|
462
|
+
props: { tools: 'all' } // every tool (default)
|
|
463
|
+
|
|
464
|
+
// 2. Explicit array — show exactly these buttons (in canonical group order)
|
|
465
|
+
props: {
|
|
466
|
+
tools: [
|
|
467
|
+
'h1', 'h2', 'p',
|
|
468
|
+
'bold', 'italic',
|
|
469
|
+
'bulletList', 'orderedList', 'blockquote',
|
|
470
|
+
'link', 'image',
|
|
471
|
+
],
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// 3. Hand-picked minimal toolbar
|
|
475
|
+
props: { tools: ['bold', 'italic', 'link'] }
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
Available tool IDs (grouped as they appear in the rendered toolbar):
|
|
479
|
+
|
|
480
|
+
| Group | Tool IDs |
|
|
481
|
+
| :---------------- | :---------------------------------------------------------------------- |
|
|
482
|
+
| History | `undo`, `redo` |
|
|
483
|
+
| Block format | `h1`, `h2`, `p` |
|
|
484
|
+
| Inline formatting | `bold`, `italic`, `underline`, `strikethrough`, `code` |
|
|
485
|
+
| Lists & blocks | `bulletList`, `orderedList`, `blockquote`, `hr`, `image` |
|
|
486
|
+
| Alignment | `alignLeft`, `alignCenter`, `alignRight` |
|
|
487
|
+
| Misc | `link`, `clearFormat` |
|
|
488
|
+
|
|
489
|
+
> Group separators are automatically hidden when both adjacent groups are empty, so the toolbar never leaves dangling dividers. The `RichTextToolId` and `RichTextTools` types are exported from `vlite3` if you want to type a schema programmatically.
|
|
490
|
+
|
|
491
|
+
#### Grouped Forms
|
|
492
|
+
|
|
493
|
+
Organize complex forms into visual groups with headings. A group is skipped entirely — header, body, and container omitted — when it has no fields to show. This applies when the schema array is empty **and** when every field is hidden by its own `when` (or other dynamic) condition, so conditionally-toggled groups collapse cleanly without leaving stranded headers above empty bodies. The original schema indices are preserved, so `groupsHeadings[i]` still lines up with the `i`-th authored group even when earlier groups are filtered out.
|
|
494
|
+
|
|
495
|
+
```vue
|
|
496
|
+
<script setup>
|
|
497
|
+
// Define schema as array of arrays
|
|
498
|
+
const schema = [
|
|
499
|
+
[
|
|
500
|
+
// Group 1: Personal
|
|
501
|
+
{ name: 'firstName', label: 'First Name', type: 'text' },
|
|
502
|
+
{ name: 'lastName', label: 'Last Name', type: 'text' },
|
|
503
|
+
],
|
|
504
|
+
[
|
|
505
|
+
// Group 2: Contact
|
|
506
|
+
{ name: 'email', label: 'Email', type: 'email' },
|
|
507
|
+
{ name: 'phone', label: 'Phone', type: 'tel' },
|
|
508
|
+
],
|
|
509
|
+
]
|
|
510
|
+
</script>
|
|
511
|
+
|
|
512
|
+
<template>
|
|
513
|
+
<Form
|
|
514
|
+
:schema="schema"
|
|
515
|
+
:groupsHeadings="['Personal Info', 'Contact Details']"
|
|
516
|
+
:groupHeadingsDescription="['Basic identification', 'How to reach you']" />
|
|
517
|
+
</template>
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
#### Dynamic Group Headings
|
|
521
|
+
|
|
522
|
+
Pass a function instead of a static array to derive headings from the current form state. The function receives the form context (`{ values, globalValues, isUpdate }`) — same shape used by `when`, `disabled`, and `readonly` — and is re-evaluated whenever those values change. Fully backward compatible with the static `string[]` form.
|
|
523
|
+
|
|
524
|
+
```vue
|
|
525
|
+
<script setup>
|
|
526
|
+
const schema = [
|
|
527
|
+
[
|
|
528
|
+
{ name: 'firstName', label: 'First Name', type: 'text' },
|
|
529
|
+
{ name: 'lastName', label: 'Last Name', type: 'text' },
|
|
530
|
+
],
|
|
531
|
+
[
|
|
532
|
+
{ name: 'email', label: 'Email', type: 'email' },
|
|
533
|
+
{ name: 'phone', label: 'Phone', type: 'tel' },
|
|
534
|
+
],
|
|
535
|
+
]
|
|
536
|
+
</script>
|
|
537
|
+
|
|
538
|
+
<template>
|
|
539
|
+
<Form
|
|
540
|
+
:schema="schema"
|
|
541
|
+
:groupsHeadings="({ values, isUpdate }) => [
|
|
542
|
+
isUpdate ? 'Editing Profile' : 'New Profile',
|
|
543
|
+
`Contact (${values.firstName || 'Unnamed'})`,
|
|
544
|
+
]"
|
|
545
|
+
:groupHeadingsDescription="({ values }) => [
|
|
546
|
+
'Basic identification',
|
|
547
|
+
values.email ? `Verified at ${values.email}` : 'No email yet',
|
|
548
|
+
]" />
|
|
549
|
+
</template>
|
|
550
|
+
```
|
|
551
|
+
|
|
552
|
+
#### Input Addons (Schema-Driven)
|
|
553
|
+
|
|
554
|
+
Use `addonLeft` and `addonRight` as objects to render dropdowns or buttons inside input addons. Each select addon binds to its own key in form state.
|
|
555
|
+
|
|
556
|
+
```vue
|
|
557
|
+
<script setup>
|
|
558
|
+
const schema = [
|
|
559
|
+
{
|
|
560
|
+
name: 'domain',
|
|
561
|
+
label: 'Website',
|
|
562
|
+
type: 'text',
|
|
563
|
+
placeholder: 'example.com',
|
|
564
|
+
// Dropdown addon on the left — writes to formValues.protocol
|
|
565
|
+
addonLeft: {
|
|
566
|
+
name: 'protocol',
|
|
567
|
+
type: 'select',
|
|
568
|
+
value: 'https://',
|
|
569
|
+
options: [
|
|
570
|
+
{ label: 'https://', value: 'https://' },
|
|
571
|
+
{ label: 'http://', value: 'http://' },
|
|
572
|
+
],
|
|
573
|
+
props: { class: 'w-24' },
|
|
574
|
+
},
|
|
575
|
+
// Button addon on the right — emits @onAddonAction
|
|
576
|
+
addonRight: {
|
|
577
|
+
type: 'button',
|
|
578
|
+
text: 'Check',
|
|
579
|
+
action: 'checkAvailability',
|
|
580
|
+
},
|
|
581
|
+
},
|
|
582
|
+
{
|
|
583
|
+
name: 'amount',
|
|
584
|
+
label: 'Price',
|
|
585
|
+
type: 'text',
|
|
586
|
+
placeholder: '0.00',
|
|
587
|
+
addonLeft: {
|
|
588
|
+
name: 'currency',
|
|
589
|
+
type: 'select',
|
|
590
|
+
value: 'USD',
|
|
591
|
+
options: [
|
|
592
|
+
{ label: 'USD', value: 'USD' },
|
|
593
|
+
{ label: 'EUR', value: 'EUR' },
|
|
594
|
+
],
|
|
595
|
+
},
|
|
596
|
+
addonRight: '.00', // Plain string addon (unchanged API)
|
|
597
|
+
},
|
|
598
|
+
]
|
|
599
|
+
|
|
600
|
+
const handleAddonAction = (action) => {
|
|
601
|
+
// action === 'checkAvailability'
|
|
602
|
+
}
|
|
603
|
+
</script>
|
|
604
|
+
|
|
605
|
+
<template>
|
|
606
|
+
<Form :schema="schema" @onSubmit="handleSubmit" @onAddonAction="handleAddonAction" />
|
|
607
|
+
</template>
|
|
608
|
+
```
|
|
609
|
+
|
|
610
|
+
> **Note:** Plain string addons (e.g. `addonLeft: '$'`) still work exactly as before — fully backward compatible.
|
|
611
|
+
|
|
612
|
+
#### Inline Layout
|
|
613
|
+
|
|
614
|
+
Use `layout="inline"` to place inputs and the submit button on the same line, ideal for newsletter signups, filters, or simple inline searches.
|
|
615
|
+
|
|
616
|
+
```vue
|
|
617
|
+
<script setup>
|
|
618
|
+
const schema = [
|
|
619
|
+
{
|
|
620
|
+
name: 'email',
|
|
621
|
+
type: 'email',
|
|
622
|
+
placeholder: 'Enter your email',
|
|
623
|
+
itemClass: 'w-80'
|
|
624
|
+
}
|
|
625
|
+
]
|
|
626
|
+
</script>
|
|
627
|
+
|
|
628
|
+
<template>
|
|
629
|
+
<Form :schema="schema" layout="inline" submitText="Subscribe" />
|
|
630
|
+
</template>
|
|
631
|
+
```
|
|
632
|
+
|
|
633
|
+
#### Page Mode
|
|
634
|
+
|
|
635
|
+
Use `isPage` to render the form in a full-page layout with a sticky header containing a back button and title.
|
|
636
|
+
|
|
637
|
+
```vue
|
|
638
|
+
<template>
|
|
639
|
+
<Form
|
|
640
|
+
:schema="schema"
|
|
641
|
+
is-page
|
|
642
|
+
page-title="Edit Profile"
|
|
643
|
+
:back-button-path="'/settings'"
|
|
644
|
+
@onSubmit="handleSubmit">
|
|
645
|
+
<template #header-actions="{ isSubmitting }">
|
|
646
|
+
<Button variant="outline" :disabled="isSubmitting">Preview</Button>
|
|
647
|
+
</template>
|
|
648
|
+
</Form>
|
|
649
|
+
</template>
|
|
650
|
+
```
|
|
651
|
+
|
|
652
|
+
#### Form in Lazy Modal (Real-world Example)
|
|
653
|
+
|
|
654
|
+
A common pattern is using a Form inside a lazy modal. The `close` method is automatically passed to the component, allowing you to close the modal after a successful submission.
|
|
655
|
+
|
|
656
|
+
**CreateFolder.vue**
|
|
657
|
+
|
|
658
|
+
```vue
|
|
659
|
+
<script setup lang="ts">
|
|
660
|
+
import { Form, showToast } from 'vlite3'
|
|
661
|
+
// Example usage with a mutation hook
|
|
662
|
+
import { useCreateFolderMutation } from '@/graphql'
|
|
663
|
+
|
|
664
|
+
interface Props {
|
|
665
|
+
parentId: string | null
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
const props = defineProps<Props>()
|
|
669
|
+
|
|
670
|
+
// Mock mutation hook
|
|
671
|
+
const { mutate: createFolder, loading: creatingFolder } = useCreateFolderMutation({
|
|
672
|
+
refetchQueries: ['GetFolders'],
|
|
673
|
+
})
|
|
674
|
+
|
|
675
|
+
const handleCreateFolder = async (payload: any, close) => {
|
|
676
|
+
try {
|
|
677
|
+
await createFolder({
|
|
678
|
+
input: {
|
|
679
|
+
name: payload.values.name,
|
|
680
|
+
parentId: props.parentId,
|
|
681
|
+
},
|
|
682
|
+
})
|
|
683
|
+
showToast('Folder created', 'success')
|
|
684
|
+
// Close the modal on success
|
|
685
|
+
close?.()
|
|
686
|
+
} catch (e: any) {
|
|
687
|
+
showToast(e.message, 'error')
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
</script>
|
|
691
|
+
|
|
692
|
+
<template>
|
|
693
|
+
<div class="p-4">
|
|
694
|
+
<Form
|
|
695
|
+
:schema="[
|
|
696
|
+
{
|
|
697
|
+
name: 'name',
|
|
698
|
+
label: 'Folder Name',
|
|
699
|
+
type: 'text',
|
|
700
|
+
required: true,
|
|
701
|
+
placeholder: 'My Documents',
|
|
702
|
+
},
|
|
703
|
+
]"
|
|
704
|
+
:loading="creatingFolder"
|
|
705
|
+
submit-text="Create Folder"
|
|
706
|
+
@on-submit="handleCreateFolder" />
|
|
707
|
+
</div>
|
|
708
|
+
</template>
|
|
709
|
+
```
|
|
710
|
+
|
|
711
|
+
**Usage in Parent Page**
|
|
712
|
+
|
|
713
|
+
```vue
|
|
714
|
+
<script setup>
|
|
715
|
+
import CreateFolder from './CreateFolder.vue'
|
|
716
|
+
</script>
|
|
717
|
+
|
|
718
|
+
<template>
|
|
719
|
+
<div>
|
|
720
|
+
<Modal
|
|
721
|
+
title="Create New Folder"
|
|
722
|
+
:body="CreateFolder"
|
|
723
|
+
max-width="max-w-md"
|
|
724
|
+
:parentId="currentFolderId">
|
|
725
|
+
<template #trigger>
|
|
726
|
+
<Button icon="lucide:folder-plus">New Folder</Button>
|
|
727
|
+
</template>
|
|
728
|
+
</Modal>
|
|
729
|
+
</div>
|
|
730
|
+
</template>
|
|
731
|
+
```
|
|
732
|
+
|
|
733
|
+
---
|
|
734
|
+
|
|
735
|
+
### Custom Components Integration
|
|
736
|
+
|
|
737
|
+
When you use a custom component in the form schema (`type: MyCustomComponent`), the Form component facilitates a two-way data flow via specific props and events.
|
|
738
|
+
|
|
739
|
+
#### 1. Data Flow Mechanism
|
|
740
|
+
|
|
741
|
+
- **Input (Props):** The Form component passes the current state to your component via the `value` prop. It also provides the entire form state via `values` for cross-field logic.
|
|
742
|
+
- **Output (Events):** Your component must emit an `onChange` event with a payload of `{ value: any }` to update the form's internal state.
|
|
743
|
+
|
|
744
|
+
#### 2. Component Interface
|
|
745
|
+
|
|
746
|
+
Your custom component should be structured like this to work seamlessly:
|
|
747
|
+
|
|
748
|
+
```vue
|
|
749
|
+
<script setup lang="ts">
|
|
750
|
+
const props = defineProps<{
|
|
751
|
+
value: any // The specific value for this field
|
|
752
|
+
values: Record<string, any> // The entire form state (for context)
|
|
753
|
+
disabled?: boolean
|
|
754
|
+
readonly?: boolean
|
|
755
|
+
}>()
|
|
756
|
+
|
|
757
|
+
const emit = defineEmits<{
|
|
758
|
+
(e: 'onChange', payload: { value: any; data?: any }): void
|
|
759
|
+
}>()
|
|
760
|
+
|
|
761
|
+
function update(newValue: any) {
|
|
762
|
+
// Always emit as an object with a 'value' key
|
|
763
|
+
emit('onChange', { value: newValue })
|
|
764
|
+
}
|
|
765
|
+
</script>
|
|
766
|
+
```
|
|
767
|
+
|
|
768
|
+
#### 3. Custom Component Schema Registration
|
|
769
|
+
|
|
770
|
+
```ts
|
|
771
|
+
{
|
|
772
|
+
name: 'myField',
|
|
773
|
+
label: 'Custom Field',
|
|
774
|
+
type: MyCustomComponent, // Pass the component definition directly
|
|
775
|
+
}
|
|
776
|
+
```
|