@uniquedj95/vform 3.7.0 → 3.7.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/README.md +265 -235
- package/dist/components/inputs/RadioInput.vue.d.ts.map +1 -1
- package/dist/components/inputs/RepeatInput.vue.d.ts.map +1 -1
- package/dist/components/vForm.vue.d.ts.map +1 -1
- package/dist/composables/useFormValidation.d.ts +0 -1
- package/dist/composables/useFormValidation.d.ts.map +1 -1
- package/dist/composables/useMultiStepForm.d.ts.map +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +929 -874
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/index.d.ts +34 -4
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/vform.css +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
|
|
7
7
|
A dynamic form builder for Vue.js with Ionic components
|
|
8
8
|
|
|
9
|
-
[](https://github.com/uniquedj95/vform/releases)
|
|
10
10
|
[](https://opensource.org/licenses/MIT)
|
|
11
11
|
[](https://vuejs.org/)
|
|
12
12
|
[](https://www.typescriptlang.org/)
|
|
13
13
|
[](https://www.npmjs.com/package/@uniquedj95/vform)
|
|
14
|
-
[](https://ionicframework.com/)
|
|
15
15
|
[](https://bundlephobia.com/package/@uniquedj95/vform)
|
|
16
16
|
[](https://github.com/uniquedj95/vform/pulls)
|
|
17
17
|
|
|
@@ -27,10 +27,12 @@ A dynamic form builder for Vue.js with Ionic components
|
|
|
27
27
|
- [Schema Structure](#schema-structure)
|
|
28
28
|
- [Example Schema](#example-schema)
|
|
29
29
|
- [Field Configuration Options](#field-configuration-options)
|
|
30
|
+
- [Input Masking](#input-masking)
|
|
30
31
|
- [Multi-Step Forms](#multi-step-forms)
|
|
31
32
|
- [Basic Multi-Step Setup](#basic-multi-step-setup)
|
|
32
33
|
- [Step Configuration](#step-configuration)
|
|
33
34
|
- [Step Indicator Positioning](#step-indicator-positioning)
|
|
35
|
+
- [Conditional Steps](#conditional-steps)
|
|
34
36
|
- [Custom Components in Steps](#custom-components-in-steps)
|
|
35
37
|
- [Step Validation](#step-validation)
|
|
36
38
|
- [Form Sections](#form-sections)
|
|
@@ -38,6 +40,7 @@ A dynamic form builder for Vue.js with Ionic components
|
|
|
38
40
|
- [Section Configuration](#section-configuration)
|
|
39
41
|
- [Form Events](#form-events)
|
|
40
42
|
- [Form Methods](#form-methods)
|
|
43
|
+
- [Composables](#composables)
|
|
41
44
|
- [Input Dependencies](#input-dependencies)
|
|
42
45
|
- [Dynamic Options](#dynamic-options)
|
|
43
46
|
- [Resetting Dependent Fields](#resetting-dependent-fields)
|
|
@@ -46,6 +49,7 @@ A dynamic form builder for Vue.js with Ionic components
|
|
|
46
49
|
- [Custom Buttons](#custom-buttons)
|
|
47
50
|
- [RepeatInput](#repeatinput)
|
|
48
51
|
- [Option Descriptions](#option-descriptions)
|
|
52
|
+
- [Component Exports](#component-exports)
|
|
49
53
|
- [Issue Reporting and Feedback](#issue-reporting-and-feedback)
|
|
50
54
|
- [Contributors](#contributors)
|
|
51
55
|
|
|
@@ -95,6 +99,7 @@ npm run demo:update
|
|
|
95
99
|
- **Custom Components**: Integrate custom Vue components directly into multi-step forms for advanced visualizations and workflows.
|
|
96
100
|
- **Form Sections**: Organize forms into logical sections with titles and subtitles for better user experience.
|
|
97
101
|
- **Dynamic Form Generation**: Create forms dynamically based on a schema definition.
|
|
102
|
+
- **Input Masking**: Built-in support for input masking using Maskito for consistent data entry formatting.
|
|
98
103
|
- **Conditional Field Rendering**: Fields can be shown or hidden based on other form values.
|
|
99
104
|
- **Dependent Options**: Load options for select inputs based on the values of other fields.
|
|
100
105
|
- **Responsive Grid Layout**: Utilizes Ionic Grid for a responsive design that works across different screen sizes.
|
|
@@ -113,31 +118,18 @@ npm run demo:update
|
|
|
113
118
|
|
|
114
119
|
1. Install the package using your preferred package manager:
|
|
115
120
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
```sh
|
|
121
|
+
```bash
|
|
119
122
|
npm install @uniquedj95/vform
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
Using Yarn:
|
|
123
|
-
|
|
124
|
-
```sh
|
|
123
|
+
# or
|
|
125
124
|
yarn add @uniquedj95/vform
|
|
125
|
+
# or
|
|
126
|
+
pnpm add @uniquedj95/vform
|
|
126
127
|
```
|
|
127
128
|
|
|
128
129
|
2. Make sure you have the required peer dependencies:
|
|
129
130
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
```sh
|
|
134
|
-
npm install @ionic/vue ionicons
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
or
|
|
138
|
-
|
|
139
|
-
```sh
|
|
140
|
-
yarn add @ionic/vue ionicons
|
|
131
|
+
```bash
|
|
132
|
+
npm install vue@^3.5.10 @ionic/vue@^8.2.5 ionicons@^8.0.9
|
|
141
133
|
```
|
|
142
134
|
|
|
143
135
|
## Usage
|
|
@@ -145,51 +137,31 @@ npm run demo:update
|
|
|
145
137
|
1. Register `VForm` component in your Vue.js application:
|
|
146
138
|
|
|
147
139
|
```typescript
|
|
148
|
-
|
|
149
|
-
import
|
|
150
|
-
import App from './App.vue';
|
|
151
|
-
import router from './router';
|
|
152
|
-
import { IonicVue } from '@ionic/vue';
|
|
153
|
-
import { VForm } from '@uniquedj95/vform';
|
|
154
|
-
|
|
155
|
-
/* Import CSS styles and other components here */
|
|
140
|
+
import { createApp } from 'vue';
|
|
141
|
+
import VForm from '@uniquedj95/vform';
|
|
156
142
|
import '@uniquedj95/vform/vform.css';
|
|
157
143
|
|
|
158
|
-
const app = createApp(
|
|
159
|
-
|
|
160
|
-
.use(VForm as Plugin)
|
|
161
|
-
.use(router);
|
|
162
|
-
|
|
163
|
-
router.isReady().then(() => {
|
|
164
|
-
app.mount('#app');
|
|
165
|
-
});
|
|
144
|
+
const app = createApp({});
|
|
145
|
+
app.use(VForm);
|
|
166
146
|
```
|
|
167
147
|
|
|
168
148
|
2. Use the component in your template:
|
|
169
149
|
|
|
170
150
|
```vue
|
|
171
151
|
<template>
|
|
172
|
-
<v-form :schema="formSchema"
|
|
152
|
+
<v-form :schema="formSchema" @submit="handleSubmit" />
|
|
173
153
|
</template>
|
|
174
154
|
|
|
175
155
|
<script setup lang="ts">
|
|
176
156
|
import { reactive } from 'vue';
|
|
177
157
|
import { FormSchema, FormData, ComputedData } from '@uniquedj95/vform';
|
|
178
158
|
|
|
179
|
-
const formSchema =
|
|
180
|
-
//
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
required: true,
|
|
186
|
-
// additional field configuration options
|
|
187
|
-
},
|
|
188
|
-
// Additional fields
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
function onSubmit(data: FormData, computedData: ComputedData) {
|
|
192
|
-
console.log(data, computedData);
|
|
159
|
+
const formSchema: FormSchema = {
|
|
160
|
+
// Your form fields here
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
function handleSubmit(formData: FormData, computedData: ComputedData) {
|
|
164
|
+
console.log('Form submitted:', { formData, computedData });
|
|
193
165
|
}
|
|
194
166
|
</script>
|
|
195
167
|
```
|
|
@@ -268,6 +240,7 @@ The following input types are supported:
|
|
|
268
240
|
| `TextAreaInput` | Multi-line text input |
|
|
269
241
|
| `SelectInput` | Dropdown selection |
|
|
270
242
|
| `CheckboxInput` | Toggle on/off input |
|
|
243
|
+
| `RadioInput` | Single selection from multiple radio options |
|
|
271
244
|
| `RepeatInput` | Repeatable group of fields |
|
|
272
245
|
| `FormSection` | Section header with title and subtitle (unified with FormField) |
|
|
273
246
|
|
|
@@ -306,11 +279,11 @@ The following input types are supported:
|
|
|
306
279
|
|
|
307
280
|
#### Text Input Properties
|
|
308
281
|
|
|
309
|
-
| Property | Type | Description
|
|
310
|
-
| ----------- | -------- |
|
|
311
|
-
| `minLength` | `number` | Minimum text length
|
|
312
|
-
| `maxLength` | `number` | Maximum text length
|
|
313
|
-
| `pattern` | `string` | Regular expression pattern for validation | Text-based inputs |
|
|
282
|
+
| Property | Type | Description | Applies To |
|
|
283
|
+
| ----------- | -------- | -------------------------------------------------------------------------- | ----------------- |
|
|
284
|
+
| `minLength` | `number` | Minimum text length | Text-based inputs |
|
|
285
|
+
| `maxLength` | `number` | Maximum text length | Text-based inputs |
|
|
286
|
+
| `pattern` | `string` | Regular expression pattern for validation and input masking (uses Maskito) | Text-based inputs |
|
|
314
287
|
|
|
315
288
|
#### Number Input Properties
|
|
316
289
|
|
|
@@ -350,6 +323,21 @@ The following input types are supported:
|
|
|
350
323
|
| ---------- | ------------ | ------------------------------------- |
|
|
351
324
|
| `children` | `FormSchema` | Schema for the repeatable field group |
|
|
352
325
|
|
|
326
|
+
#### RadioInput Properties
|
|
327
|
+
|
|
328
|
+
| Property | Type | Description |
|
|
329
|
+
| ---------------------- | ------------- | ---------------------------------------------------------------- |
|
|
330
|
+
| `options` | `FormOptions` | Array of options or function returning options |
|
|
331
|
+
| `showOptionsSeparator` | `boolean` | Whether to show lines between radio options |
|
|
332
|
+
| `compareWith` | `Function` | Custom comparison function for option selection |
|
|
333
|
+
| `allowEmptySelection` | `boolean` | Whether to allow deselecting all options (defaults to !required) |
|
|
334
|
+
|
|
335
|
+
#### CheckboxInput Properties
|
|
336
|
+
|
|
337
|
+
| Property | Type | Description |
|
|
338
|
+
| --------- | --------- | ------------------------------------- |
|
|
339
|
+
| `checked` | `boolean` | Initial checked state of the checkbox |
|
|
340
|
+
|
|
353
341
|
### Custom Styling with className
|
|
354
342
|
|
|
355
343
|
All form input components now support the `className` property for custom styling. This allows you to apply CSS classes to individual input fields and form sections for complete visual customization.
|
|
@@ -428,6 +416,61 @@ The `className` property is supported across all input components:
|
|
|
428
416
|
- **RepeatInput**: Applied to each repeat group wrapper
|
|
429
417
|
- **FormSection**: Applied to the section container
|
|
430
418
|
|
|
419
|
+
### Input Masking
|
|
420
|
+
|
|
421
|
+
vForm includes built-in support for input masking using [Maskito](https://maskito.dev/), which provides consistent data entry formatting for various input types.
|
|
422
|
+
|
|
423
|
+
#### Basic Usage
|
|
424
|
+
|
|
425
|
+
Use the `pattern` property on text-based inputs to apply masking:
|
|
426
|
+
|
|
427
|
+
```typescript
|
|
428
|
+
const formSchema: FormSchema = {
|
|
429
|
+
phoneNumber: {
|
|
430
|
+
type: 'TextInput',
|
|
431
|
+
label: 'Phone Number',
|
|
432
|
+
pattern: '+1 (000) 000-0000',
|
|
433
|
+
placeholder: '+1 (555) 123-4567',
|
|
434
|
+
},
|
|
435
|
+
creditCard: {
|
|
436
|
+
type: 'TextInput',
|
|
437
|
+
label: 'Credit Card',
|
|
438
|
+
pattern: '0000 0000 0000 0000',
|
|
439
|
+
placeholder: '1234 5678 9012 3456',
|
|
440
|
+
},
|
|
441
|
+
socialSecurity: {
|
|
442
|
+
type: 'TextInput',
|
|
443
|
+
label: 'SSN',
|
|
444
|
+
pattern: '000-00-0000',
|
|
445
|
+
placeholder: '123-45-6789',
|
|
446
|
+
},
|
|
447
|
+
};
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
#### Common Mask Patterns
|
|
451
|
+
|
|
452
|
+
| Pattern | Description | Example Output |
|
|
453
|
+
| ----------------------- | ------------------ | --------------------- |
|
|
454
|
+
| `'000-00-0000'` | US Social Security | `123-45-6789` |
|
|
455
|
+
| `'+1 (000) 000-0000'` | US Phone Number | `+1 (555) 123-4567` |
|
|
456
|
+
| `'0000 0000 0000 0000'` | Credit Card | `1234 5678 9012 3456` |
|
|
457
|
+
| `'00/00/0000'` | Date (MM/DD/YYYY) | `12/25/2023` |
|
|
458
|
+
| `'00:00'` | Time (HH:MM) | `14:30` |
|
|
459
|
+
|
|
460
|
+
#### Advanced Masking
|
|
461
|
+
|
|
462
|
+
For more complex masking requirements, you can use regular expressions:
|
|
463
|
+
|
|
464
|
+
```typescript
|
|
465
|
+
const emailMask = {
|
|
466
|
+
type: 'EmailInput',
|
|
467
|
+
label: 'Email',
|
|
468
|
+
pattern: '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$',
|
|
469
|
+
};
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
The masking is automatically applied when the user types, providing real-time formatting and validation feedback.
|
|
473
|
+
|
|
431
474
|
## Multi-Step Forms
|
|
432
475
|
|
|
433
476
|
vForm supports multi-step forms with configurable step indicators, validation, and smart navigation. Multi-step forms break complex forms into manageable sections, improving user experience and data collection.
|
|
@@ -698,165 +741,6 @@ When a step is hidden:
|
|
|
698
741
|
> updateStepData('step-to-be-hidden', backupData);
|
|
699
742
|
> ```
|
|
700
743
|
|
|
701
|
-
### Custom Components in Steps
|
|
702
|
-
|
|
703
|
-
vForm allows you to use custom Vue components in multi-step forms instead of schema-defined fields. This is useful for complex steps that require custom layouts, visualizations, or integration with other components.
|
|
704
|
-
|
|
705
|
-
```vue
|
|
706
|
-
<template>
|
|
707
|
-
<v-form
|
|
708
|
-
:multi-step-config="multiStepConfig"
|
|
709
|
-
@multi-step-submit="handleSubmit"
|
|
710
|
-
@step-change="handleStepChange"
|
|
711
|
-
/>
|
|
712
|
-
</template>
|
|
713
|
-
|
|
714
|
-
<script setup lang="ts">
|
|
715
|
-
import { defineComponent, ref } from 'vue';
|
|
716
|
-
import { MultiStepConfig } from '@uniquedj95/vform';
|
|
717
|
-
import PreviousResultsTable from './PreviousResultsTable.vue';
|
|
718
|
-
|
|
719
|
-
// Define your custom component
|
|
720
|
-
const PreviousResultsTable = defineComponent({
|
|
721
|
-
props: {
|
|
722
|
-
data: Object,
|
|
723
|
-
},
|
|
724
|
-
setup(props, { emit }) {
|
|
725
|
-
// Implement your component logic
|
|
726
|
-
const tableData = ref([
|
|
727
|
-
/* your data */
|
|
728
|
-
]);
|
|
729
|
-
|
|
730
|
-
// Custom validation function - will be called when clicking "Next"
|
|
731
|
-
function validate() {
|
|
732
|
-
// Add your validation logic here
|
|
733
|
-
return true; // Return true if valid, false if not
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
// Function to update data in the parent form
|
|
737
|
-
function updateData() {
|
|
738
|
-
emit('update:data', {
|
|
739
|
-
/* your component data */
|
|
740
|
-
});
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
return { tableData, validate, updateData };
|
|
744
|
-
},
|
|
745
|
-
});
|
|
746
|
-
|
|
747
|
-
const multiStepConfig: MultiStepConfig = {
|
|
748
|
-
steps: [
|
|
749
|
-
{
|
|
750
|
-
id: 'patient-info',
|
|
751
|
-
title: 'Patient Information',
|
|
752
|
-
schema: {
|
|
753
|
-
// Standard form schema
|
|
754
|
-
patientId: {
|
|
755
|
-
type: 'TextInput',
|
|
756
|
-
label: 'Patient ID',
|
|
757
|
-
required: true,
|
|
758
|
-
},
|
|
759
|
-
// More fields...
|
|
760
|
-
},
|
|
761
|
-
},
|
|
762
|
-
{
|
|
763
|
-
id: 'previous-results',
|
|
764
|
-
title: 'Previous ANC Results',
|
|
765
|
-
// Use a custom component instead of a schema
|
|
766
|
-
component: PreviousResultsTable,
|
|
767
|
-
componentProps: {
|
|
768
|
-
// Props to pass to your component
|
|
769
|
-
clinicId: 123,
|
|
770
|
-
showDetails: true,
|
|
771
|
-
},
|
|
772
|
-
},
|
|
773
|
-
{
|
|
774
|
-
id: 'new-visit',
|
|
775
|
-
title: 'New ANC Visit',
|
|
776
|
-
schema: {
|
|
777
|
-
// Back to standard form schema
|
|
778
|
-
visitDate: {
|
|
779
|
-
type: 'DateInput',
|
|
780
|
-
label: 'Visit Date',
|
|
781
|
-
required: true,
|
|
782
|
-
},
|
|
783
|
-
// More fields...
|
|
784
|
-
},
|
|
785
|
-
},
|
|
786
|
-
],
|
|
787
|
-
stepPosition: 'top',
|
|
788
|
-
showProgress: true,
|
|
789
|
-
allowStepNavigation: true,
|
|
790
|
-
};
|
|
791
|
-
</script>
|
|
792
|
-
```
|
|
793
|
-
|
|
794
|
-
#### Custom Component Requirements
|
|
795
|
-
|
|
796
|
-
To work properly with the multi-step form, your custom component should:
|
|
797
|
-
|
|
798
|
-
1. **Accept Props**: Receive data and configuration through props
|
|
799
|
-
2. **Emit Data Updates**: Use `emit('update:data', yourData)` to send data back to the form
|
|
800
|
-
3. **Implement Validation**: Expose a `validate()` method that returns a boolean or promise resolving to boolean
|
|
801
|
-
|
|
802
|
-
#### Component Interface Example
|
|
803
|
-
|
|
804
|
-
```vue
|
|
805
|
-
<template>
|
|
806
|
-
<div class="custom-step-component">
|
|
807
|
-
<!-- Your custom UI here -->
|
|
808
|
-
<data-table :data="tableData" @row-click="selectRow" />
|
|
809
|
-
|
|
810
|
-
<!-- You can still use Ionic components -->
|
|
811
|
-
<ion-button @click="handleSave">Save Selection</ion-button>
|
|
812
|
-
</div>
|
|
813
|
-
</template>
|
|
814
|
-
|
|
815
|
-
<script setup>
|
|
816
|
-
import { ref } from 'vue';
|
|
817
|
-
|
|
818
|
-
const props = defineProps({
|
|
819
|
-
// Your props here
|
|
820
|
-
initialData: Object,
|
|
821
|
-
});
|
|
822
|
-
|
|
823
|
-
const emits = defineEmits(['update:data']);
|
|
824
|
-
|
|
825
|
-
const tableData = ref([]);
|
|
826
|
-
const selectedRow = ref(null);
|
|
827
|
-
|
|
828
|
-
function selectRow(row) {
|
|
829
|
-
selectedRow.value = row;
|
|
830
|
-
emitData();
|
|
831
|
-
}
|
|
832
|
-
|
|
833
|
-
function handleSave() {
|
|
834
|
-
// Your save logic
|
|
835
|
-
emitData();
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
function emitData() {
|
|
839
|
-
// Send data back to parent form
|
|
840
|
-
emits('update:data', {
|
|
841
|
-
selected: selectedRow.value,
|
|
842
|
-
// other data...
|
|
843
|
-
});
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
// This method will be called for validation
|
|
847
|
-
function validate() {
|
|
848
|
-
// Return false if validation fails
|
|
849
|
-
if (!selectedRow.value) {
|
|
850
|
-
return false;
|
|
851
|
-
}
|
|
852
|
-
return true;
|
|
853
|
-
}
|
|
854
|
-
|
|
855
|
-
// Expose the validate method to the parent
|
|
856
|
-
defineExpose({ validate });
|
|
857
|
-
</script>
|
|
858
|
-
```
|
|
859
|
-
|
|
860
744
|
### Step Validation
|
|
861
745
|
|
|
862
746
|
Multi-step forms include built-in validation that prevents users from proceeding to the next step until the current step is valid:
|
|
@@ -894,12 +778,13 @@ const multiStepConfig: MultiStepConfig = {
|
|
|
894
778
|
|
|
895
779
|
### Multi-Step Configuration Options
|
|
896
780
|
|
|
897
|
-
| Property | Type | Description | Default
|
|
898
|
-
| --------------------- | ---------------------------------------- | --------------------------------------------- |
|
|
899
|
-
| `steps` | `FormStep[]` | Array of step configurations | Required
|
|
900
|
-
| `stepPosition` | `'top' \| 'bottom' \| 'left' \| 'right'` | Position of the step indicator | `'top'`
|
|
901
|
-
| `
|
|
902
|
-
| `
|
|
781
|
+
| Property | Type | Description | Default |
|
|
782
|
+
| --------------------- | ---------------------------------------- | --------------------------------------------- | ----------- |
|
|
783
|
+
| `steps` | `FormStep[]` | Array of step configurations | Required |
|
|
784
|
+
| `stepPosition` | `'top' \| 'bottom' \| 'left' \| 'right'` | Position of the step indicator | `'top'` |
|
|
785
|
+
| `stepDisplayMode` | `'numbers' \| 'labels'` | Display mode for step indicators | `'numbers'` |
|
|
786
|
+
| `showProgress` | `boolean` | Show progress bar and step counter | `true` |
|
|
787
|
+
| `allowStepNavigation` | `boolean` | Allow clicking on step indicators to navigate | `false` |
|
|
903
788
|
|
|
904
789
|
### Multi-Step Events
|
|
905
790
|
|
|
@@ -1079,22 +964,89 @@ You can customize section appearance using the `className` property and your own
|
|
|
1079
964
|
|
|
1080
965
|
## Form Events
|
|
1081
966
|
|
|
967
|
+
### Single-Step Form Events
|
|
968
|
+
|
|
1082
969
|
| Event | Description | Signature |
|
|
1083
970
|
| -------- | ---------------------------------------------------------------- | -------------------------------------------------------------- |
|
|
1084
971
|
| `submit` | Emitted when the form is submitted successfully after validation | `(formData: FormData, computedFormData: ComputedData) => void` |
|
|
1085
972
|
| `clear` | Emitted when the form fields are cleared to their initial state | `() => void` |
|
|
1086
973
|
| `cancel` | Emitted when the form submission is canceled, resetting fields | `() => void` |
|
|
1087
974
|
|
|
975
|
+
### Multi-Step Form Events
|
|
976
|
+
|
|
977
|
+
| Event | Description | Signature |
|
|
978
|
+
| ------------------- | ----------------------------------------- | --------------------------------------------- |
|
|
979
|
+
| `multi-step-submit` | Emitted when multi-step form is submitted | `(data: multiStepData) => void` |
|
|
980
|
+
| `step-change` | Emitted when user navigates between steps | `(stepIndex: number, stepId: string) => void` |
|
|
981
|
+
|
|
982
|
+
The `multi-step-submit` event provides both the combined data from all steps and the per-step data structure:
|
|
983
|
+
|
|
984
|
+
```typescript
|
|
985
|
+
// multi-step data structure
|
|
986
|
+
multiStepData: MultiStepFormData = {
|
|
987
|
+
formData: {
|
|
988
|
+
personal: { firstName: 'John', lastName: 'Doe' },
|
|
989
|
+
contact: { email: 'john@example.com' },
|
|
990
|
+
// ... other step data
|
|
991
|
+
},
|
|
992
|
+
computedData: {
|
|
993
|
+
personal: { fullName: 'John Doe' },
|
|
994
|
+
contact: { domain: 'example.com' },
|
|
995
|
+
// ... other computed step data
|
|
996
|
+
},
|
|
997
|
+
};
|
|
998
|
+
```
|
|
999
|
+
|
|
1088
1000
|
## Form Methods
|
|
1089
1001
|
|
|
1090
1002
|
When accessing the VForm via a template ref, you can utilize these methods:
|
|
1091
1003
|
|
|
1004
|
+
### Single-Step Form Methods
|
|
1005
|
+
|
|
1092
1006
|
| Method | Description | Return Type |
|
|
1093
1007
|
| --------------- | ------------------------------------------------------ | ---------------------------------------------------- |
|
|
1094
1008
|
| `resetForm()` | Resets all form fields to their initial state | `void` |
|
|
1095
1009
|
| `isFormValid()` | Validates all form fields and returns validation state | `Promise<boolean>` |
|
|
1096
1010
|
| `resolveData()` | Returns the current form data and computed data | `{ formData: FormData, computedData: ComputedData }` |
|
|
1097
1011
|
|
|
1012
|
+
### Multi-Step Form Methods
|
|
1013
|
+
|
|
1014
|
+
| Method | Description | Return Type |
|
|
1015
|
+
| ----------------------- | ---------------------------------------- | ----------------------- |
|
|
1016
|
+
| `nextStep()` | Moves to the next step (with validation) | `Promise<void>` |
|
|
1017
|
+
| `previousStep()` | Moves to the previous step | `void` |
|
|
1018
|
+
| `goToStep(index)` | Navigates to a specific step by index | `Promise<void>` |
|
|
1019
|
+
| `getCurrentStep()` | Returns the current step configuration | `FormStep \| undefined` |
|
|
1020
|
+
| `getCurrentStepIndex()` | Returns the current step index | `number` |
|
|
1021
|
+
|
|
1022
|
+
## Composables
|
|
1023
|
+
|
|
1024
|
+
vForm exports several composables that you can use to build custom form solutions or extend functionality:
|
|
1025
|
+
|
|
1026
|
+
### Available Composables
|
|
1027
|
+
|
|
1028
|
+
| Composable | Description | Use Case |
|
|
1029
|
+
| ----------------------- | -------------------------------------------------- | --------------------------------------------- |
|
|
1030
|
+
| `useFormValidation` | Core form validation logic and state management | Building custom form wrappers |
|
|
1031
|
+
| `useInputValidation` | Input-specific validation and error handling | Creating custom input components |
|
|
1032
|
+
| `useDataTransformation` | Data transformation and computed value handling | Processing form data for display/submission |
|
|
1033
|
+
| `useDependentOptions` | Managing dependent field options and relationships | Dynamic option loading and field dependencies |
|
|
1034
|
+
| `useMultiStepForm` | Multi-step form navigation and state management | Custom multi-step form implementations |
|
|
1035
|
+
|
|
1036
|
+
### Example Usage
|
|
1037
|
+
|
|
1038
|
+
```typescript
|
|
1039
|
+
import { useFormValidation, useInputValidation } from '@uniquedj95/vform';
|
|
1040
|
+
|
|
1041
|
+
// In your custom form component
|
|
1042
|
+
const { isValid, validateForm, getErrors } = useFormValidation();
|
|
1043
|
+
|
|
1044
|
+
// In your custom input component
|
|
1045
|
+
const { onValueUpdate, onFocus, getErrors } = useInputValidation(inputRef, model, input, schema);
|
|
1046
|
+
```
|
|
1047
|
+
|
|
1048
|
+
For detailed usage examples of these composables, see the [source code](./src/composables/) or examine how they're used in the built-in components.
|
|
1049
|
+
|
|
1098
1050
|
## Input Dependencies
|
|
1099
1051
|
|
|
1100
1052
|
vForm provides a powerful system for creating dependent form inputs, where the options displayed in one input depend on the values selected in another. This is especially useful for hierarchical selections like country → state → city or category → subcategory.
|
|
@@ -1383,19 +1335,97 @@ When using SelectInput or CheckboxInput, you can add descriptions to options:
|
|
|
1383
1335
|
|
|
1384
1336
|
### Form Props
|
|
1385
1337
|
|
|
1386
|
-
| Property
|
|
1387
|
-
|
|
|
1388
|
-
| `schema`
|
|
1389
|
-
| `multiStepConfig`
|
|
1390
|
-
| `showLabels`
|
|
1391
|
-
| `showClearButton`
|
|
1392
|
-
| `showCancelButton`
|
|
1393
|
-
| `buttonPlacement`
|
|
1394
|
-
| `submitButtonText`
|
|
1395
|
-
| `clearButtonText`
|
|
1396
|
-
| `cancelButtonText`
|
|
1397
|
-
| `
|
|
1398
|
-
| `
|
|
1338
|
+
| Property | Type | Description | Default |
|
|
1339
|
+
| -------------------- | ------------------------------ | ---------------------------------------------------------------------- | ------------ |
|
|
1340
|
+
| `schema` | `FormSchema` | The schema object defining the form structure and field configurations | _Required_ |
|
|
1341
|
+
| `multiStepConfig` | `MultiStepConfig` | Configuration for multi-step forms (optional) | `undefined` |
|
|
1342
|
+
| `showLabels` | `boolean` | Determines if labels are displayed for each field | `true` |
|
|
1343
|
+
| `showClearButton` | `boolean` | Controls the visibility of the clear/reset button | `true` |
|
|
1344
|
+
| `showCancelButton` | `boolean` | Controls the visibility of the cancel button | `true` |
|
|
1345
|
+
| `buttonPlacement` | `'start' \| 'middle' \| 'end'` | Specifies the alignment of action buttons within the form | `'start'` |
|
|
1346
|
+
| `submitButtonText` | `string` | Custom text for the submit button | `"Submit"` |
|
|
1347
|
+
| `clearButtonText` | `string` | Custom text for the clear/reset button | `"Reset"` |
|
|
1348
|
+
| `cancelButtonText` | `string` | Custom text for the cancel button | `"Cancel"` |
|
|
1349
|
+
| `nextButtonText` | `string` | Custom text for the next button (multi-step forms) | `"Next"` |
|
|
1350
|
+
| `previousButtonText` | `string` | Custom text for the previous button (multi-step forms) | `"Previous"` |
|
|
1351
|
+
| `hideButtons` | `boolean` | When true, hides all action buttons | `false` |
|
|
1352
|
+
| `customButtons` | `Array<CustomButton>` | Array of custom buttons to add to the form | `[]` |
|
|
1353
|
+
|
|
1354
|
+
## Component Exports
|
|
1355
|
+
|
|
1356
|
+
vForm exports individual components that you can use directly in your applications for more granular control:
|
|
1357
|
+
|
|
1358
|
+
### Available Components
|
|
1359
|
+
|
|
1360
|
+
```typescript
|
|
1361
|
+
import {
|
|
1362
|
+
VForm, // Main form component
|
|
1363
|
+
FormBuilder, // Alias for VForm
|
|
1364
|
+
TextInput,
|
|
1365
|
+
DateInput,
|
|
1366
|
+
NumberInput,
|
|
1367
|
+
EmailInput,
|
|
1368
|
+
PasswordInput,
|
|
1369
|
+
SelectInput,
|
|
1370
|
+
TextAreaInput,
|
|
1371
|
+
RepeatInput,
|
|
1372
|
+
CheckboxInput,
|
|
1373
|
+
RadioInput,
|
|
1374
|
+
FormSection,
|
|
1375
|
+
} from '@uniquedj95/vform';
|
|
1376
|
+
```
|
|
1377
|
+
|
|
1378
|
+
### Usage Example
|
|
1379
|
+
|
|
1380
|
+
```vue
|
|
1381
|
+
<template>
|
|
1382
|
+
<div>
|
|
1383
|
+
<!-- Use individual components directly -->
|
|
1384
|
+
<TextInput v-model="textField" />
|
|
1385
|
+
<SelectInput v-model="selectField" />
|
|
1386
|
+
<CheckboxInput v-model="checkboxField" />
|
|
1387
|
+
|
|
1388
|
+
<!-- Or use within a custom form -->
|
|
1389
|
+
<form @submit="handleSubmit">
|
|
1390
|
+
<DateInput v-model="dateField" />
|
|
1391
|
+
<NumberInput v-model="numberField" />
|
|
1392
|
+
<ion-button type="submit">Submit</ion-button>
|
|
1393
|
+
</form>
|
|
1394
|
+
</div>
|
|
1395
|
+
</template>
|
|
1396
|
+
|
|
1397
|
+
<script setup lang="ts">
|
|
1398
|
+
import { ref } from 'vue';
|
|
1399
|
+
import { TextInput, SelectInput, CheckboxInput, DateInput, NumberInput } from '@uniquedj95/vform';
|
|
1400
|
+
import { FormField } from '@uniquedj95/vform';
|
|
1401
|
+
|
|
1402
|
+
const textField = ref<FormField>({
|
|
1403
|
+
type: 'TextInput',
|
|
1404
|
+
label: 'Name',
|
|
1405
|
+
placeholder: 'Enter your name',
|
|
1406
|
+
});
|
|
1407
|
+
|
|
1408
|
+
const selectField = ref<FormField>({
|
|
1409
|
+
type: 'SelectInput',
|
|
1410
|
+
label: 'Country',
|
|
1411
|
+
options: [
|
|
1412
|
+
{ label: 'USA', value: 'us' },
|
|
1413
|
+
{ label: 'Canada', value: 'ca' },
|
|
1414
|
+
],
|
|
1415
|
+
});
|
|
1416
|
+
|
|
1417
|
+
// ... other field definitions
|
|
1418
|
+
</script>
|
|
1419
|
+
```
|
|
1420
|
+
|
|
1421
|
+
### Component Props
|
|
1422
|
+
|
|
1423
|
+
All individual components accept the following props:
|
|
1424
|
+
|
|
1425
|
+
| Prop | Type | Description | Required |
|
|
1426
|
+
| --------- | ------------ | -------------------------------------------------------- | -------- |
|
|
1427
|
+
| `v-model` | `FormField` | The form field configuration object | ✓ |
|
|
1428
|
+
| `schema` | `FormSchema` | Optional schema for validation and dependency resolution | No |
|
|
1399
1429
|
|
|
1400
1430
|
## Issue Reporting and Feedback
|
|
1401
1431
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RadioInput.vue.d.ts","sourceRoot":"","sources":["../../../src/components/inputs/RadioInput.vue"],"names":[],"mappings":"AA0CA;
|
|
1
|
+
{"version":3,"file":"RadioInput.vue.d.ts","sourceRoot":"","sources":["../../../src/components/inputs/RadioInput.vue"],"names":[],"mappings":"AA0CA;AAmIA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAU,MAAM,SAAS,CAAC;AAMxD,KAAK,WAAW,GAAG;IAAE,MAAM,CAAC,EAAE,UAAU,CAAA;CAAE,CAAC;AAE3C,QAAA,MAAM,KAAK,iEAAoE,CAAC;AAehF,iBAAS,OAAO,SAIf;AA4CD,KAAK,iBAAiB,GAAG;IACzB,UAAU,CAAC,EAAE,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC;CAClC,GAAG,WAAW,CAAC;;;;;;;;;;;AAyLhB,wBAQG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RepeatInput.vue.d.ts","sourceRoot":"","sources":["../../../src/components/inputs/RepeatInput.vue"],"names":[],"mappings":"AAwDA;
|
|
1
|
+
{"version":3,"file":"RepeatInput.vue.d.ts","sourceRoot":"","sources":["../../../src/components/inputs/RepeatInput.vue"],"names":[],"mappings":"AAwDA;AAmMA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAU,MAAM,SAAS,CAAC;AAOhF,UAAU,MAAM;IACd,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,IAAI,EAAE,QAAQ,CAAC;IACf,YAAY,EAAE,YAAY,CAAC;CAC5B;AAED,KAAK,WAAW,GAAG,MAAM,CAAC;AAE1B,QAAA,MAAM,KAAK,iEAAoE,CAAC;AA2ChF,iBAAS,OAAO,SAqBf;AAED,iBAAS,SAAS,aAEjB;AAED,iBAAe,aAAa,kBAE3B;AAiBD,KAAK,iBAAiB,GAAG;IACzB,UAAU,CAAC,EAAE,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC;CAClC,GAAG,WAAW,CAAC;;;;;;;;;;;;AA0OhB,wBASG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vForm.vue.d.ts","sourceRoot":"","sources":["../../src/components/vForm.vue"],"names":[],"mappings":"AAkMA;
|
|
1
|
+
{"version":3,"file":"vForm.vue.d.ts","sourceRoot":"","sources":["../../src/components/vForm.vue"],"names":[],"mappings":"AAkMA;AA8mBA,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAkIpF,iBAAS,iBAAiB,SAOzB;AAmBD,iBAAe,cAAc,kBAyB5B;AAED,iBAAe,kBAAkB,kBAOhC;AAED,iBAAe,eAAe,CAAC,SAAS,EAAE,MAAM,iBA2B/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6sBD,wBAWG"}
|