@volverjs/form-vue 0.0.1 → 0.0.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 CHANGED
@@ -73,10 +73,13 @@ A `valid` or `invalid` event is emitted when the form status changes.
73
73
  const onSubmit = (formData) => {
74
74
  // Do something with the form data
75
75
  }
76
+ const onInvalid = (errors) => {
77
+ // Do something with the errors
78
+ }
76
79
  </script>
77
80
 
78
81
  <template>
79
- <VvForm @submit="onSubmit">
82
+ <VvForm @submit="onSubmit" @invalid="onInvalid">
80
83
  <!-- form fields -->
81
84
  <button type="submit">Submit</button>
82
85
  </VvForm>
@@ -87,7 +90,10 @@ The submit can be triggered programmatically with the `submit()` method.
87
90
 
88
91
  ```vue
89
92
  <script lang="ts" setup>
90
- const formEl = ref(null)
93
+ import { ref } from 'vue'
94
+ import type { FormComponent } from '@volverjs/form-vue'
95
+
96
+ const formEl = ref<InstanceType<FormComponent>>(null)
91
97
  const onSubmit = (formData) => {
92
98
  // Do something with the form data
93
99
  }
@@ -121,7 +127,6 @@ The throttle can be changed with the `updateThrottle` option.
121
127
  <template>
122
128
  <VvForm v-model="formData">
123
129
  <!-- form fields -->
124
- <button type="submit">Submit</button>
125
130
  </VvForm>
126
131
  </template>
127
132
  ```
@@ -134,13 +139,13 @@ The wrapper status is invalid if at least one of the fields inside it is invalid
134
139
  ```vue
135
140
  <template>
136
141
  <VvForm>
137
- <VvFormWrapper #default="{ invalid }">
142
+ <VvFormWrapper v-slot="{ invalid }">
138
143
  <div class="form-section-1">
139
144
  <span v-if="invalid">There is a validation error</span>
140
145
  <!-- form fields of section 1 -->
141
146
  </div>
142
147
  </VvFormWrapper>
143
- <VvFormWrapper #default="{ invalid }">
148
+ <VvFormWrapper v-slot="{ invalid }">
144
149
  <div class="form-section-2">
145
150
  <span v-if="invalid">There is a validation error</span>
146
151
  <!-- form fields of the section 2 -->
@@ -150,6 +155,27 @@ The wrapper status is invalid if at least one of the fields inside it is invalid
150
155
  </template>
151
156
  ```
152
157
 
158
+ `VvFormWrapper` can be used recursively to create a validation tree. The wrapper status is invalid if at least one of the fields inside it or one of its children is invalid.
159
+
160
+ ```vue
161
+ <template>
162
+ <VvForm>
163
+ <VvFormWrapper v-slot="{ invalid }">
164
+ <div class="form-section">
165
+ <span v-if="invalid">There is a validation error</span>
166
+ <!-- form fields of section -->
167
+ <VvFormWrapper v-slot="{ invalid: groupInvalid }">
168
+ <div class="form-section__group">
169
+ <span v-if="groupInvalid">There is a validation error</span>
170
+ <!-- form fields of the group -->
171
+ </div>
172
+ </VvFormWrapper>
173
+ </div>
174
+ </VvFormWrapper>
175
+ </VvForm>
176
+ </template>
177
+ ```
178
+
153
179
  ### VvFormField
154
180
 
155
181
  `VvFormField` allow you to render a [`@volverjs/ui-vue`](https://github.com/volverjs/ui-vue) input component inside a form. It automatically bind the form data through the `name` attribute.
@@ -176,14 +202,13 @@ For nested objects, use the `name` attribute with dot notation.
176
202
  The type of input component is defined by the `type` attribute.
177
203
  All the available input types are listed in the [VvFormField documentation](/docs/VvFormField.md).
178
204
 
179
- You can also use the `VvFormField` component to render a default slot without .
205
+ You can also use the `VvFormField` component to render a default slot without a `type` (default `type` is `custom`).
180
206
 
181
207
  ```vue
182
208
  <template>
183
209
  <VvForm>
184
210
  <VvFormField
185
- name="name"
186
- #default="{
211
+ v-slot="{
187
212
  modelValue,
188
213
  invalid,
189
214
  invalidLabel,
@@ -192,17 +217,18 @@ You can also use the `VvFormField` component to render a default slot without .
192
217
  erros,
193
218
  onUpdate
194
219
  }"
220
+ name="surname"
195
221
  >
196
- <label for="name">Name</label>
222
+ <label for="surname">Surname</label>
197
223
  <input
198
- id="name"
224
+ id="surname"
199
225
  type="text"
200
226
  :value="modelValue"
201
227
  :aria-invalid="invalid"
202
- :aria-errormessage="invalid ? 'name-alert' : undefined"
228
+ :aria-errormessage="invalid ? 'surname-alert' : undefined"
203
229
  @input="onUpdate"
204
230
  />
205
- <small v-if="invalid" role="alert" id="name-alert">
231
+ <small v-if="invalid" role="alert" id="surname-alert">
206
232
  {{ invalidLabel }}
207
233
  </small>
208
234
  </VvFormField>
@@ -219,7 +245,7 @@ Or a custom component.
219
245
 
220
246
  <template>
221
247
  <VvForm>
222
- <VvFormField name="name" :is="MyInput" />
248
+ <VvFormField name="surname" :is="MyInput" />
223
249
  </VvForm>
224
250
  </template>
225
251
  ```
@@ -227,7 +253,7 @@ Or a custom component.
227
253
  ## Composable
228
254
 
229
255
  `useForm` can be used to create a form programmatically inside a Vue 3 Component.
230
- If the plugin is defined globally, the settings are inherited but can be customized.
256
+ The default settings are inherited from the plugin (if it was defined).
231
257
 
232
258
  ```vue
233
259
  <script lang="ts" setup>
@@ -257,6 +283,7 @@ If the plugin is defined globally, the settings are inherited but can be customi
257
283
  ## Outside a Vue 3 Component
258
284
 
259
285
  `formFactory` can be used to create a form outside a Vue 3 Component.
286
+ No settings are inherited.
260
287
 
261
288
  ```ts
262
289
  import { formFactory } from '@volverjs/form-vue'
package/dist/index.d.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  import { type InjectionKey, type Plugin } from 'vue';
2
2
  import type { AnyZodObject } from 'zod';
3
+ import { defineFormField } from './VvFormField';
4
+ import { defineForm } from './VvForm';
5
+ import { defineFormWrapper } from './VvFormWrapper';
3
6
  import type { InjectedFormData, InjectedFormWrapperData, InjectedFormFieldData, FormComposableOptions, FormPluginOptions } from './types';
4
7
  export declare const formFactory: (schema: AnyZodObject, options?: FormComposableOptions) => {
5
8
  VvForm: import("vue").DefineComponent<{
@@ -119,4 +122,7 @@ export declare const useForm: (schema: AnyZodObject, options?: FormComposableOpt
119
122
  };
120
123
  export { FormFieldType } from './enums';
121
124
  export { defaultObjectBySchema } from './utils';
122
- export type { InjectedFormData, InjectedFormWrapperData, InjectedFormFieldData, FormComposableOptions, FormPluginOptions, };
125
+ type FormComponent = ReturnType<typeof defineForm>;
126
+ type FormWrapperComponent = ReturnType<typeof defineFormWrapper>;
127
+ type FormFieldComponent = ReturnType<typeof defineFormField>;
128
+ export type { InjectedFormData, InjectedFormWrapperData, InjectedFormFieldData, FormComposableOptions, FormPluginOptions, FormComponent, FormWrapperComponent, FormFieldComponent, };
package/package.json CHANGED
@@ -19,7 +19,7 @@
19
19
  "bugs": {
20
20
  "url": "https://github.com/volverjs/form-vue/issues"
21
21
  },
22
- "version": "0.0.1",
22
+ "version": "0.0.2",
23
23
  "engines": {
24
24
  "node": ">= 16.x"
25
25
  },
@@ -34,8 +34,6 @@
34
34
  "*.d.ts"
35
35
  ],
36
36
  "dependencies": {
37
- "@iconify/tools": "^2.2.6",
38
- "@iconify/vue": "^4.1.0",
39
37
  "@volverjs/ui-vue": "0.0.5-beta.1",
40
38
  "@vueuse/core": "^9.13.0",
41
39
  "deepmerge": "^4.3.0",
package/src/index.ts CHANGED
@@ -88,10 +88,17 @@ export const useForm = (
88
88
  export { FormFieldType } from './enums'
89
89
  export { defaultObjectBySchema } from './utils'
90
90
 
91
+ type FormComponent = ReturnType<typeof defineForm>
92
+ type FormWrapperComponent = ReturnType<typeof defineFormWrapper>
93
+ type FormFieldComponent = ReturnType<typeof defineFormField>
94
+
91
95
  export type {
92
96
  InjectedFormData,
93
97
  InjectedFormWrapperData,
94
98
  InjectedFormFieldData,
95
99
  FormComposableOptions,
96
100
  FormPluginOptions,
101
+ FormComponent,
102
+ FormWrapperComponent,
103
+ FormFieldComponent,
97
104
  }