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

Commit 17d521b

Browse files
author
Daniel Requejo
committed
Merge branch 'master' into feature/10-cleanup-before-first-release
2 parents 7b77067 + 5d3cc1e commit 17d521b

27 files changed

+498
-57
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**Working on your first Pull Request?** You can learn how from this *free* series [How to Contribute to an Open Source Project on GitHub](https://kcd.im/pull-request)

README.md

Lines changed: 95 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,102 @@
1-
# Vue 3 + TypeScript + Vite
21

3-
This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
2+
<div align="center">
3+
<h1>vue-form-handler</h1>
44

5-
## Recommended IDE Setup
5+
The easy way of handling your vue forms
6+
</div>
67

7-
- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar)
8+
[![Build Status](https://github.com/mattphillips/deep-object-diff/actions/workflows/ci.yaml/badge.svg)](https://github.com/dbssman/vue-form-handler/actions/workflows/node.js.yml)
9+
[![version](https://img.shields.io/npm/v/deep-object-diff.svg?style=flat-square)](https://www.npmjs.com/package/deep-object-diff)
10+
[![downloads](https://img.shields.io/npm/dm/deep-object-diff.svg?style=flat-square)](http://npm-stat.com/charts.html?package=deep-object-diff&from=2016-11-23)
11+
[![MIT License](https://img.shields.io/npm/l/deep-object-diff.svg?style=flat-square)](https://github.com/dbssman/vue-form-handler/blob/master/License.md)
12+
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
813

9-
## Type Support For `.vue` Imports in TS
14+
## 📦 Installation
15+
---
16+
``` yarn add vue-form-handler ```
1017

11-
Since TypeScript cannot handle type information for `.vue` imports, they are shimmed to be a generic Vue component type by default. In most cases this is fine if you don't really care about component prop types outside of templates. However, if you wish to get actual prop types in `.vue` imports (for example to get props validation when using manual `h(...)` calls), you can enable Volar's Take Over mode by following these steps:
18+
``` npm i --save vue-form-handler ```
1219

13-
1. Run `Extensions: Show Built-in Extensions` from VS Code's command palette, look for `TypeScript and JavaScript Language Features`, then right click and select `Disable (Workspace)`. By default, Take Over mode will enable itself if the default TypeScript extension is disabled.
14-
2. Reload the VS Code window by running `Developer: Reload Window` from the command palette.
20+
## 🚀 Features
21+
---
22+
- 💪 **Type strong**: Written in TypeScript
23+
- 🔩 **Flexible**: you can wrap the form handler over native inputs or any other like the ones from material libraries or custom inputs.
24+
- 🪶 **Super light**: Small package size
25+
- 💻 **DX**: Great development experience
1526

16-
You can learn more about Take Over mode [here](https://github.com/johnsoncodehk/volar/discussions/471).
27+
## 🦄 Usage
28+
---
29+
### Basic usage
30+
31+
```vue
32+
<template>
33+
<form @submit.prevent="handleSubmit(successFn)">
34+
<input v-bind="register('firstName')" />
35+
<input v-bind="register('lastName')" />
36+
<input v-bind="register('age')" type="number"/>
37+
<input type="submit"/>
38+
</form>
39+
</template>
40+
<script setup lang="ts" >
41+
import { useFormHandler } from 'vue-form-handler';
42+
const { register, handleSubmit } = useFormHandler();
43+
const successFn = (form: Record<string,any>) => {console.log({form})}
44+
</script>
45+
```
46+
47+
### Validations
48+
49+
```vue
50+
<template>
51+
<form @submit.prevent="handleSubmit(successFn)">
52+
<input v-bind="register('firstName',{
53+
required:'This field is required'
54+
})" />
55+
<p>{{formState.errors.firstName}}</p>
56+
<input v-bind="register('lastName')" />
57+
<input v-bind="register('age', {
58+
min:{
59+
value: 18,
60+
message: 'Your age is below the accepted range'
61+
}
62+
})" type="number" />
63+
<p>{{formState.errors.age}}</p>
64+
<input type="submit"/>
65+
</form>
66+
</template>
67+
<script setup lang="ts" >
68+
import { useFormHandler } from 'vue-form-handler';
69+
const { formState, register, handleSubmit } = useFormHandler();
70+
const successFn = (form: Record<string,any>) => {console.log({form})}
71+
</script>
72+
```
73+
74+
### Integration with Material frameworks
75+
76+
```vue
77+
<template>
78+
<form @submit.prevent="handleSubmit(successFn)">
79+
<q-input v-bind="register('name')" />
80+
<q-checkbox v-bind="register('married')"/>
81+
<q-select v-bind="register('pet')" :options="['dog','cat','mouse']"/>
82+
<input type="submit"/>
83+
</form>
84+
</template>
85+
<script setup lang="ts" >
86+
import { useFormHandler } from 'vue-form-handler';
87+
const { formState, register, handleSubmit } = useFormHandler();
88+
const successFn = (form: Record<string,any>) => {console.log({form})}
89+
</script>
90+
```
91+
92+
### For a more advanced usage visit the [Docs](https://vue-form-handler.com)
93+
94+
## 💜 Thanks
95+
---
96+
This project is heavily inspired by other awesome projects like:
97+
- [jaredpalmer/formik](https://github.com/jaredpalmer/formik)
98+
- [react-hook-form/react-hook-form](https://github.com/react-hook-form/react-hook-form)
99+
100+
## 📄 License
101+
---
102+
[MIT License](https://github.com/dbssman/vue-form-handler/blob/master/License.md) © 2022-PRESENT [Dennis Bosmans](https://github.com/dbssman)

docs/.vitepress/config.cts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
import { defineConfig } from "vitepress"
22

33
export default defineConfig({
4-
title: 'Vue form handler',
4+
title: 'VueFormHandler',
55
description: 'Discover the easy way of handling your vue forms',
66
themeConfig: {
7+
logo: '/favicon.svg',
8+
editLink: {
9+
pattern: 'https://github.com/dbssman/vue-form-handler/edit/master/docs/:path',
10+
text: 'Edit this page on GitHub',
11+
},
712
nav: [
813
{ text: 'Home', link: '/' },
9-
{ text: 'Get started', link: '/getting-started' },
14+
{ text: 'Get started', link: '/get-started' },
1015
],
1116
sidebar: [
1217
{
1318
text: 'Documentation', items: [
14-
{ text: 'Get started', link: '/getting-started' },
19+
{ text: 'Get started', link: '/get-started' },
1520
{ text: 'Tutorial', link: '/tutorial' },
1621
{
1722
text: 'Guides', items: [
@@ -36,7 +41,23 @@ export default defineConfig({
3641
},
3742
{
3843
text: 'API Reference', items: [
39-
{ text: 'useFormHandler()', link: '/api/use-form-handler' },
44+
{
45+
text: 'useFormHandler', link: '/api/use-form-handler/index', items: [
46+
{ text: 'clearError', link: '/api/use-form-handler/clear-error' },
47+
{ text: 'clearField', link: '/api/use-form-handler/clear-field' },
48+
{ text: 'formState', link: '/api/use-form-handler/form-state' },
49+
{ text: 'handleSubmit', link: '/api/use-form-handler/handle-submit' },
50+
{ text: 'modifiedValues', link: '/api/use-form-handler/modified-values' },
51+
{ text: 'register', link: '/api/use-form-handler/register' },
52+
{ text: 'resetField', link: '/api/use-form-handler/reset-field' },
53+
{ text: 'resetForm', link: '/api/use-form-handler/reset-form' },
54+
{ text: 'setError', link: '/api/use-form-handler/set-error' },
55+
{ text: 'setValue', link: '/api/use-form-handler/set-value' },
56+
{ text: 'triggerValidation', link: '/api/use-form-handler/trigger-validation' },
57+
{ text: 'unregister', link: '/api/use-form-handler/unregister' },
58+
{ text: 'values', link: '/api/use-form-handler/values' },
59+
]
60+
},
4061
{ text: `FormHandler`, link: '/api/form-handler' }
4162
]
4263
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# clearError
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# clearField
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# formState
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# handleSubmit
File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# modifiedValues

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# register

0 commit comments

Comments
 (0)