|
1 |
| -# Vue 3 + TypeScript + Vite |
2 | 1 |
|
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> |
4 | 4 |
|
5 |
| -## Recommended IDE Setup |
| 5 | +The easy way of handling your vue forms |
| 6 | +</div> |
6 | 7 |
|
7 |
| -- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) |
| 8 | +[](https://github.com/dbssman/vue-form-handler/actions/workflows/node.js.yml) |
| 9 | +[](https://www.npmjs.com/package/deep-object-diff) |
| 10 | +[](http://npm-stat.com/charts.html?package=deep-object-diff&from=2016-11-23) |
| 11 | +[](https://github.com/dbssman/vue-form-handler/blob/master/License.md) |
| 12 | +[](http://makeapullrequest.com) |
8 | 13 |
|
9 |
| -## Type Support For `.vue` Imports in TS |
| 14 | +## 📦 Installation |
| 15 | +--- |
| 16 | +``` yarn add vue-form-handler ``` |
10 | 17 |
|
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 ``` |
12 | 19 |
|
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 |
15 | 26 |
|
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> |
| 41 | +import { useFormHandler } from 'vue-form-handler'; |
| 42 | +const { register, handleSubmit } = useFormHandler(); |
| 43 | +const successFn = (form) => {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> |
| 68 | +import { useFormHandler } from 'vue-form-handler'; |
| 69 | +const { formState, register, handleSubmit } = useFormHandler(); |
| 70 | +const successFn = (form) => {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> |
| 86 | +import { useFormHandler } from 'vue-form-handler'; |
| 87 | +const { formState, register, handleSubmit } = useFormHandler(); |
| 88 | +const successFn = (form) => {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) |
0 commit comments