Skip to content
This repository was archived by the owner on Apr 9, 2025. It is now read-only.

Commit 8badb18

Browse files
author
Daniel Requejo
committed
⚡️ WIP: Api reference
1 parent 8d307e5 commit 8badb18

File tree

15 files changed

+136
-58
lines changed

15 files changed

+136
-58
lines changed

docs/.vitepress/config.cts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,36 @@ export default defineConfig({
2020
},
2121
nav: [
2222
{ text: 'Home', link: '/' },
23-
{ text: 'Get started', link: '/get-started' },
23+
{ text: 'Get started', link: '/get-started/introduction' },
2424
],
2525
sidebar: [
2626
{
27-
text: 'Documentation', items: [
28-
{ text: 'Get started', link: '/get-started' },
29-
{ text: 'Tutorial', link: '/tutorial' },
30-
{
31-
text: 'Guides', items: [
32-
{ text: 'Validation', link: '/guides/validation' },
33-
{ text: 'Typescript', link: '/guides/typescript' },
34-
{ text: 'Form submission', link: '/guides/form-submission' },
35-
{ text: 'Custom components', link: '/guides/custom-components' },
36-
{ text: 'Native support', link: '/guides/native-support' },
37-
]
38-
},
39-
{
40-
text: 'Examples', items: [
41-
{ text: 'Basic', link: '/examples/basic' },
42-
{ text: 'Async validations', link: '/examples/async-validations' },
43-
{ text: 'Typescript', link: '/examples/typescript' },
44-
{ text: 'Interceptor', link: '/examples/interceptor' },
45-
{ text: 'Dependent fields', link: '/examples/dependent-fields' },
46-
{ text: 'More examples', link: '/examples/more-examples' }
47-
]
48-
},
27+
text: 'Get started', items: [
28+
{ text: 'Introduction', link: '/get-started/introduction' },
29+
{ text: 'Quick Start', link: '/get-started/quick-start' },
30+
]
31+
},
32+
{
33+
text: 'Guides', collapsible: true, items: [
34+
{ text: 'Validation', link: '/guides/validation' },
35+
{ text: 'Typescript', link: '/guides/typescript' },
36+
{ text: 'Form submission', link: '/guides/form-submission' },
37+
{ text: 'Custom components', link: '/guides/custom-components' },
38+
{ text: 'Native support', link: '/guides/native-support' },
39+
]
40+
},
41+
{
42+
text: 'Examples', collapsible: true, items: [
43+
{ text: 'Basic', link: '/examples/basic' },
44+
{ text: 'Async validations', link: '/examples/async-validations' },
45+
{ text: 'Typescript', link: '/examples/typescript' },
46+
{ text: 'Interceptor', link: '/examples/interceptor' },
47+
{ text: 'Dependent fields', link: '/examples/dependent-fields' },
48+
{ text: 'More examples', link: '/examples/more-examples' }
4949
]
5050
},
5151
{
52-
text: 'API Reference', items: [
52+
text: 'API Reference', collapsible: true, items: [
5353
{
5454
text: 'useFormHandler', link: '/api/use-form-handler/',
5555
items: [

docs/api/form-handler.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# \<FormHandler/>: <font size="3">Component</font>
1+
# \<FormHandler/>
22

33
The `FormHandler` component is an utility for people that are still using the options API or, that for some reason want to do the handling on the template side.
44

docs/api/use-form-handler/clear-error.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# clearError: <font size="3">ClearError</font>
1+
# clearError
22

33
Clears all the errors from the form or the error from a field programmatically.
44

@@ -20,7 +20,7 @@ Coming soon...
2020
</form>
2121
</template>
2222
<script setup lang="ts" >
23-
import { useFormHandler, Interceptor } from '../src/index'
23+
import { useFormHandler, Interceptor } from 'vue-form-handler'
2424
2525
const sleep = (milliseconds: number) => {
2626
return new Promise(resolve => setTimeout(resolve, milliseconds))
@@ -65,7 +65,7 @@ Notice how we use the combination of [setError](/api/use-form-handler/set-error)
6565
</form>
6666
</template>
6767
<script setup lang="ts" >
68-
import { useFormHandler } from '../src/index'
68+
import { useFormHandler } from 'vue-form-handler'
6969
import { watch } from 'vue'
7070
7171
let hasErrorsAfterSubmit = false;

docs/api/use-form-handler/clear-field.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# clearField: <font size="3">ClearField</font>
1+
# clearField
22

33
Clears a field, this means that the field is set to it's default value or to the fallback value.
44
This will also trigger a validation for the field if existing.
@@ -53,7 +53,7 @@ const { register } = useFormHandler({
5353
<button @click="clearField('clearableField')">X</button>
5454
</template>
5555
<script setup lang="ts" >
56-
import { useFormHandler } from '../src/index'
56+
import { useFormHandler } from 'vue-form-handler'
5757
5858
const { register, clearField } = useFormHandler()
5959
</script>

docs/api/use-form-handler/form-state.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# formState: <font size="3">FormState</font>
1+
# formState
22

33
Provides you with the reactive state of the form, including validation, dirty and touched state, for the whole form or individual fields.
44

@@ -35,13 +35,13 @@ Provides you with the reactive state of the form, including validation, dirty an
3535
</form>
3636
</template>
3737
<script setup lang="ts" >
38-
import { useFormHandler } from '../src/index'
38+
import { useFormHandler } from 'vue-form-handler'
3939
4040
const { register, formState } = useFormHandler()
4141
</script>
4242
```
4343

44-
## Type Declaration
44+
## Type Declarations
4545

4646
```ts
4747
export interface FormState {

docs/api/use-form-handler/handle-submit.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# handleSubmit: <font size="3">HandleSubmit</font>
1+
# handleSubmit
22

33
Submits the form on demand, causing it's validation depending on the mode/validation function, and calls the success/error fn consequently based on the outcome.
44

@@ -24,7 +24,7 @@ Coming soon...
2424
</form>
2525
</template>
2626
<script setup lang="ts" >
27-
import { useFormHandler } from '../src/index'
27+
import { useFormHandler } from 'vue-form-handler'
2828
2929
const { register, handleSubmit, formState } = useFormHandler()
3030
const successFn = (form: any) => {
@@ -58,7 +58,7 @@ const submitFn = () => {
5858
</form>
5959
</template>
6060
<script setup lang="ts" >
61-
import { useFormHandler } from '../src/index'
61+
import { useFormHandler } from 'vue-form-handler'
6262
6363
const { register, handleSubmit } = useFormHandler()
6464
const successFn = (form: any) => {
@@ -72,7 +72,7 @@ const errorFn = (errors:any) => {
7272
</script>
7373
```
7474

75-
## Type Declaration
75+
## Type Declarations
7676

7777
```ts
7878
export type HandleSubmitSuccessFn = (values: Record<string, any>) => void

docs/api/use-form-handler/index.md

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# useFormHandler: <font size=3>FormHandler</font>
1+
# useFormHandler
22

33
`useFormHandler` is our composable to handle forms, it takes one object as **optional** argument and returns various objects and methods that will allow us to handle our forms.
44

@@ -157,4 +157,48 @@ Using the `always` validationMode will have a more significant impact on perform
157157
- [setValue](/api/use-form-handler/set-value)
158158
- [triggerValidation](/api/use-form-handler/trigger-validation)
159159
- [unregister](/api/use-form-handler/unregister)
160-
- [values](/api/use-form-handler/values)
160+
- [values](/api/use-form-handler/values)
161+
162+
## Type Declarations
163+
164+
```ts
165+
166+
export type Interceptor = (
167+
_: InterceptorParams
168+
) => Promise<boolean> | boolean
169+
170+
export type FormValidation = (
171+
values: Record<string, any>
172+
) => Promise<boolean> | boolean
173+
174+
export interface FormHandlerParams {
175+
initialValues?: Record<string, any>
176+
| Ref<Record<string, any>>
177+
| ComputedRef<Record<string, any>>
178+
interceptor?: Interceptor
179+
validate?: FormValidation
180+
validationMode?: 'onChange'
181+
| 'onBlur'
182+
| 'onSubmit'
183+
| 'always'
184+
}
185+
export interface FormHandlerReturn {
186+
formState: FormState
187+
values: Record<string, any>
188+
clearError: ClearError
189+
clearField: ClearField
190+
handleSubmit: HandleSubmit
191+
modifiedValues: ModifiedValues
192+
register: Register
193+
resetField: ResetField
194+
resetForm: ResetForm
195+
setError: SetError
196+
setValue: SetValue
197+
triggerValidation: TriggerValidation
198+
unregister: (name: string) => void
199+
}
200+
201+
export type FormHandler = (
202+
_?: FormHandlerParams
203+
) => FormHandlerReturn
204+
```
Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,43 @@
1-
# modifiedValues
1+
# modifiedValues
2+
3+
Returns the current modified fields of the form.
4+
5+
## Demo
6+
7+
Coming soon...
8+
9+
## Usage
10+
11+
```vue
12+
<template>
13+
<form>
14+
<input type="text" v-bind="register('name')" />
15+
<input type="text" v-bind="register('email')" />
16+
<input type="text" v-bind="register('summary')">
17+
<pre>
18+
{{ modifiedValues() }} //should be initially
19+
</pre>
20+
<pre>
21+
{{ values }} //should be filled with the initial values
22+
</pre>
23+
</form>
24+
</template>
25+
<script setup lang="ts" >
26+
import { useFormHandler } from 'vue-form-handler'
27+
28+
const { register, values, modifiedValues } = useFormHandler({
29+
initialValues: {
30+
name: 'My name',
31+
email: 'myemail@mail.com'
32+
}
33+
})
34+
</script>
35+
```
36+
37+
Let's say your form is initialized as above, because you're editing an existing item, and you just want to be aware of the data that changed to perform a `PATCH` operation, then `modifiedValues` is your best friend.
38+
39+
## Type Declarations
40+
41+
```ts
42+
export type ModifiedValues = () => Record<string, any>
43+
```

docs/api/use-form-handler/values.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# values: <font size="3">Record<string, any></font>
1+
# values
22

33
Provides you with the reactive state of the form, including validation, dirty and touched state, for the whole form or individual fields.
44

@@ -30,13 +30,13 @@ Provides you with the reactive state of the form, including validation, dirty an
3030
</section>
3131
</template>
3232
<script setup lang="ts" >
33-
import { useFormHandler } from '../src/index'
33+
import { useFormHandler } from 'vue-form-handler'
3434
3535
const { register, values } = useFormHandler()
3636
</script>
3737
```
3838

39-
## Type Declaration
39+
## Type Declarations
4040

4141
```ts
4242
export type Values = Record<string, any>

docs/get-started.md renamed to docs/get-started/introduction.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Get started
1+
# Introduction
22

33
VueFormHandler is an abstract and flexible form handling solution. It allows you to easily handle forms in Vue, without forcing you to use specific components. You can use it on along with native HTML, custom components and material libraries (Quasar, Vuetify, Oruga...). It builds on top of Vue using typescript and provides a comfortable and efficient way to handle your forms.
44

0 commit comments

Comments
 (0)