|
1 |
| -<h1 align="center"> |
2 |
| -vue-use-form(WIP) |
| 1 | + <h1 align="center"> |
| 2 | + vue-use-form |
3 | 3 | </h1>
|
4 |
| - |
5 |
| -Inspired by [react-hook-form](https://react-hook-form.com/), if you love react-hook-form usage, come on and try it! |
6 |
| - |
7 |
| -## Document |
8 |
| - |
9 |
| -The usage is almost the same as that of the react-hook-form. you can go [react-hook-form](https://react-hook-form.com/) to check. |
| 4 | +<p align="center"> |
| 5 | +Inspired by <a href="https://react-hook-form.com/">react-hook-form</a>, if you love react-hook-form usage, come on and try it! |
| 6 | +</p> |
| 7 | +<p align="center"> |
| 8 | + <a href="https://vue-use-form.netlify.app/">📝Document</a> |
| 9 | + | |
| 10 | + <a href="https://vue-use-form-play.netlify.app/"> |
| 11 | + 🤽♀️Playground |
| 12 | + </a> |
| 13 | +</p> |
10 | 14 |
|
11 | 15 | ## Install
|
12 | 16 |
|
13 | 17 | ```bash
|
14 |
| -# npm |
15 | 18 | npm i vue-use-form
|
16 |
| - |
17 |
| -# pnpm |
18 |
| -pnpm i vue-use-form |
19 |
| - |
20 |
| -# yarn |
21 |
| -yarn add vue-use-form |
22 | 19 | ```
|
23 | 20 |
|
24 | 21 | ## 🚀Features
|
25 | 22 | - 🦾 Type Strong: Written in TypeScript
|
26 | 23 | - 🏆 No Component: No need to import any components to use, you can use it in all UI framework
|
27 |
| -- 😍 Easy to use: Just 3 main hooks: useForm, useFormState, useFieldArray |
28 |
| - |
29 |
| -## TODO |
30 |
| - |
31 |
| -- [ ] 🐵Main features |
32 |
| - - [ ] 🍉`useForm` |
33 |
| - - [ ] 🍎 register -> disabled -> setValueAsDate |
34 |
| - - [ ] register -> support custom modelValue like `v-model:checked` |
35 |
| - - [ ] 🍊`useFormState` |
36 |
| - - [ ] 🍋`useFieldArray` |
37 |
| - - [ ] 🍎schema |
38 |
| - - [x] 🍵 class-validator |
39 |
| - - [x] 🍶 Yup |
40 |
| -- [ ] Test |
41 |
| - - [ ] 🐯Unit test |
42 |
| -- [ ] 🐼 Community(WIP...) |
43 |
| - - [ ] 🎋中文文档 |
44 |
| - - [ ] 📖Documentation . |
45 |
| - |
| 24 | +- 😍 Easy to use: Just 2 main hooks: useForm, useFieldArray |
46 | 25 |
|
47 |
| -## 🎁Try it online |
48 |
| -🎮[play with element-plus](https://stackblitz.com/edit/vitejs-vite-typsyz?file=src%2Fmain.ts,src%2FApp.vue,package.json&terminal=dev) by default way. |
49 | 26 |
|
50 |
| -🎮[play with class-validator](https://stackblitz.com/edit/vitejs-vite-foumka?file=src%2FApp.vue,vite.config.ts,src%2Fmain.ts,package.json,src%2Fenv.d.ts&terminal=dev) by using `class-validator` resolver |
51 |
| - |
52 |
| -## 🚣playground |
53 |
| -you can fork/download this repo, and then just 3 steps can make playground run |
54 |
| -```bash |
55 |
| -# 1. open this repo folder in your local |
56 |
| -# 2. init dependencies |
57 |
| -pnpm i |
58 |
| -# 3. open the playground folder and run `dev` script or |
59 |
| -pnpm run dev |
60 |
| -``` |
61 | 27 |
|
62 | 28 | ## Quick Start
|
63 |
| - |
64 |
| -```vue |
| 29 | +```html |
65 | 30 | <script setup lang="ts">
|
66 | 31 | import { useForm } from 'vue-use-form'
|
67 | 32 |
|
68 | 33 | interface Inputs {
|
69 |
| - age: number |
| 34 | + username: string |
70 | 35 | }
|
71 | 36 |
|
72 |
| -const { |
73 |
| - formState, |
74 |
| - register, |
75 |
| - createSubmitHandler, |
76 |
| - createErrorHandler, |
77 |
| -} = useForm<Inputs>({ |
78 |
| - mode: 'onChange', |
79 |
| - shouldFocusError: true, |
80 |
| -}) |
81 |
| -
|
82 |
| -const onSubmit = createSubmitHandler((data) => { |
83 |
| - console.log('validate success', data) |
84 |
| -}) |
85 |
| -
|
86 |
| -const onError = createErrorHandler((errors) => { |
87 |
| - console.log('validate error', errors) |
88 |
| -}) |
| 37 | +const { regsiter } = useForm<Inputs>() |
89 | 38 | </script>
|
90 | 39 |
|
91 | 40 | <template>
|
92 |
| - <form @submit.prevent="handleSubmit(onSubmit, onError)()"> |
93 |
| - <input |
94 |
| - :="register('age', { |
95 |
| - required: 'Age is required!', |
96 |
| - min: { value: 18, message: 'Age must be at least 18' }, |
97 |
| - max: { value: 10000, message: '?' }, |
98 |
| - valueAsNumber: true, |
99 |
| - })" |
100 |
| - type="number" |
101 |
| - name="age" |
102 |
| - > |
103 |
| - <button type="submit" v-text="'Submit'" /> |
104 |
| - </form> |
| 41 | + <input |
| 42 | + :="register('username', { |
| 43 | + required: 'username field cannot be empty!' |
| 44 | + })" |
| 45 | + > |
105 | 46 | </template>
|
106 | 47 | ```
|
107 | 48 |
|
| 49 | + |
108 | 50 | ## use with schema
|
109 | 51 | - [@vue-use-form/class-validator](https://github.com/vue-use-form/vue-use-form/tree/master/packages/resolver-class-validator)
|
110 | 52 | - [@vue-use-form/yup](https://github.com/vue-use-form/vue-use-form/tree/master/packages/resolver-yup)
|
0 commit comments