Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔧 Fix submit issue & add prettier #58

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ name: CI

on:
push:
branches: [ "master" ]
branches: ['master']
pull_request:
branches: [ "master" ]
branches: ['master']

jobs:
build:
Expand All @@ -33,7 +33,7 @@ jobs:

- name: Package build test
run: npm run build --if-present

unit-test:
name: Unit testing
runs-on: ubuntu-latest
Expand All @@ -46,8 +46,8 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: '18'

- run: npm ci

- name: Unit tests
run: npm run test
4 changes: 2 additions & 2 deletions .github/workflows/package-size-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Package Size Report

on:
pull_request:
branches: [ master ]
branches: [master]

jobs:
pkg-size-report:
Expand All @@ -21,4 +21,4 @@ jobs:
- name: Package size report
uses: pkg-size/action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Ignore artifacts:
build
coverage
5 changes: 5 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"trailingComma": "es5",
"semi": false
}
7 changes: 2 additions & 5 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"recommendations": [
"Vue.volar",
"Vue.vscode-typescript-vue-plugin"
]
}
"recommendations": ["Vue.volar", "Vue.vscode-typescript-vue-plugin"]
}
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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)
**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)
2 changes: 1 addition & 1 deletion License.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
117 changes: 72 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

<div align="center">
<object data="https://vue-form-handler.com/favicon.png"></object>
<h1>vue-form-handler</h1>
Expand All @@ -12,99 +11,127 @@ The easy way of handling your vue forms
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)

<a href="https://www.buymeacoffee.com/dbssman" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174"></a>
</div>

</div>

## 📦 Installation

---
``` yarn add vue-form-handler ```

``` npm i --save vue-form-handler ```
`yarn add vue-form-handler`

`npm i --save vue-form-handler`

## 🚀 Features

---

- 💪 **Type strong**: Written in TypeScript
- 🔩 **Flexible**: you can wrap the form handler over native inputs or any other like the ones from material libraries or custom inputs.
- 🪶 **Super light**: Small package size
- 💻 **DX**: Great development experience

## 🦄 Usage

---

### Basic usage

```vue
<template>
<form @submit.prevent="handleSubmit(successFn)">
<input v-bind="register('firstName')" />
<input v-bind="register('lastName')" />
<input v-bind="register('age')" type="number"/>
<input type="submit"/>
</form>
<form @submit.prevent="handleSubmit(successFn)">
<input v-bind="register('firstName')" />
<input v-bind="register('lastName')" />
<input v-bind="register('age')" type="number" />
<input type="submit" />
</form>
</template>
<script setup lang="ts" >
import { useFormHandler } from 'vue-form-handler';
const { register, handleSubmit } = useFormHandler();
const successFn = (form: Record<string,any>) => {console.log({form})}
<script setup lang="ts">
import { useFormHandler } from 'vue-form-handler'
const { register, handleSubmit } = useFormHandler()
const successFn = (form: Record<string, any>) => {
console.log({ form })
}
</script>
```

### Validations

```vue
<template>
<form @submit.prevent="handleSubmit(successFn)">
<input v-bind="register('firstName',{
required:'This field is required'
})" />
<p>{{formState.errors.firstName}}</p>
<input v-bind="register('lastName')" />
<input v-bind="register('age', {
min:{
value: 18,
message: 'Your age is below the accepted range'
}
})" type="number" />
<p>{{formState.errors.age}}</p>
<input type="submit"/>
</form>
<form @submit.prevent="handleSubmit(successFn)">
<input
v-bind="
register('firstName', {
required: 'This field is required',
})
"
/>
<p>{{ formState.errors.firstName }}</p>
<input v-bind="register('lastName')" />
<input
v-bind="
register('age', {
min: {
value: 18,
message: 'Your age is below the accepted range',
},
})
"
type="number"
/>
<p>{{ formState.errors.age }}</p>
<input type="submit" />
</form>
</template>
<script setup lang="ts" >
import { useFormHandler } from 'vue-form-handler';
const { formState, register, handleSubmit } = useFormHandler();
const successFn = (form: Record<string,any>) => {console.log({form})}
<script setup lang="ts">
import { useFormHandler } from 'vue-form-handler'
const { formState, register, handleSubmit } = useFormHandler()
const successFn = (form: Record<string, any>) => {
console.log({ form })
}
</script>
```

### Integration with Material frameworks

```vue
<template>
<form @submit.prevent="handleSubmit(successFn)">
<q-input v-bind="register('name')" />
<q-checkbox v-bind="register('married')"/>
<q-select v-bind="register('pet')" :options="['dog','cat','mouse']"/>
<input type="submit"/>
</form>
<form @submit.prevent="handleSubmit(successFn)">
<q-input v-bind="register('name')" />
<q-checkbox v-bind="register('married')" />
<q-select v-bind="register('pet')" :options="['dog', 'cat', 'mouse']" />
<input type="submit" />
</form>
</template>
<script setup lang="ts" >
import { useFormHandler } from 'vue-form-handler';
const { formState, register, handleSubmit } = useFormHandler();
const successFn = (form: Record<string,any>) => {console.log({form})}
<script setup lang="ts">
import { useFormHandler } from 'vue-form-handler'
const { formState, register, handleSubmit } = useFormHandler()
const successFn = (form: Record<string, any>) => {
console.log({ form })
}
</script>
```

### For a more advanced usage visit the [Docs](https://vue-form-handler.com)

## 📈 Project activity

---
![Alt](https://repobeats.axiom.co/api/embed/d0da4b79bde282068c5f3da3505091b1447a1f6c.svg "Repobeats analytics image")

![Alt](https://repobeats.axiom.co/api/embed/d0da4b79bde282068c5f3da3505091b1447a1f6c.svg 'Repobeats analytics image')

## 💜 Thanks

---

This project is heavily inspired by other awesome projects like:

- [jaredpalmer/formik](https://github.com/jaredpalmer/formik)
- [react-hook-form/react-hook-form](https://github.com/react-hook-form/react-hook-form)

## 📄 License

---
[MIT License](https://github.com/dbssman/vue-form-handler/blob/master/License.md) © 2022-PRESENT [Dennis Bosmans](https://github.com/dbssman)

[MIT License](https://github.com/dbssman/vue-form-handler/blob/master/License.md) © 2022-PRESENT [Dennis Bosmans](https://github.com/dbssman)
75 changes: 53 additions & 22 deletions docs/.vitepress/config.cts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineConfig } from "vitepress"
import { defineConfig } from 'vitepress'

export default defineConfig({
title: 'VueFormHandler',
Expand All @@ -9,17 +9,31 @@ export default defineConfig({
['link', { rel: 'icon', href: '/favicon.svg', type: 'image/svg+xml' }],
['meta', { name: 'author', content: 'Dennis R. Bosmans' }],
['meta', { property: 'og:title', content: 'VueFormHandler' }],
['meta', { property: 'og:image', content: 'https://vue-form-handler.com/favicon.png' }],
['meta', { property: 'og:description', content: 'The only handler you\'ll need to easily work with forms in vue' }],
[
'meta',
{
property: 'og:image',
content: 'https://vue-form-handler.com/favicon.png',
},
],
[
'meta',
{
property: 'og:description',
content:
"The only handler you'll need to easily work with forms in vue",
},
],
],
themeConfig: {
logo: '/favicon.svg',
editLink: {
pattern: 'https://github.com/dbssman/vue-form-handler/edit/master/docs/:path',
pattern:
'https://github.com/dbssman/vue-form-handler/edit/master/docs/:path',
text: 'Edit this page on GitHub',
},
socialLinks: [
{ icon: 'github', link: 'https://github.com/dbssman/vue-form-handler' }
{ icon: 'github', link: 'https://github.com/dbssman/vue-form-handler' },
],
footer: {
message: 'Released under the MIT License.',
Expand All @@ -31,51 +45,68 @@ export default defineConfig({
],
sidebar: [
{
text: 'Get started', items: [
text: 'Get started',
items: [
{ text: 'Introduction', link: '/get-started/introduction' },
{ text: 'Quick Start', link: '/get-started/quick-start' },
]
],
},
{
text: 'Guides', collapsible: true, items: [
text: 'Guides',
collapsible: true,
items: [
{ text: 'Custom components', link: '/guides/custom-components' },
{ text: 'Material libraries', link: '/guides/material-libraries' },
{ text: 'Native support', link: '/guides/native-support' },
{ text: 'Typescript', link: '/guides/typescript' },
{ text: 'Validation', link: '/guides/validation' },
]
],
},
{
text: 'Examples', collapsible: true, items: [
text: 'Examples',
collapsible: true,
items: [
{ text: 'Async submission', link: '/examples/async-submission' },
{ text: 'Async validations', link: '/examples/async-validations' },
{ text: 'Basic', link: '/examples/basic' },
{ text: 'Dependent fields', link: '/examples/dependent-fields' },
]
],
},
{
text: 'API Reference', collapsible: true, items: [
text: 'API Reference',
collapsible: true,
items: [
{
text: 'useFormHandler', link: '/api/use-form-handler/',
text: 'useFormHandler',
link: '/api/use-form-handler/',
items: [
{ text: 'clearError', link: '/api/use-form-handler/clear-error' },
{ text: 'clearField', link: '/api/use-form-handler/clear-field' },
{ text: 'formState', link: '/api/use-form-handler/form-state' },
{ text: 'handleSubmit', link: '/api/use-form-handler/handle-submit' },
{ text: 'modifiedValues', link: '/api/use-form-handler/modified-values' },
{
text: 'handleSubmit',
link: '/api/use-form-handler/handle-submit',
},
{
text: 'modifiedValues',
link: '/api/use-form-handler/modified-values',
},
{ text: 'register', link: '/api/use-form-handler/register' },
{ text: 'resetField', link: '/api/use-form-handler/reset-field' },
{ text: 'resetForm', link: '/api/use-form-handler/reset-form' },
{ text: 'setError', link: '/api/use-form-handler/set-error' },
{ text: 'setValue', link: '/api/use-form-handler/set-value' },
{ text: 'triggerValidation', link: '/api/use-form-handler/trigger-validation' },
{
text: 'triggerValidation',
link: '/api/use-form-handler/trigger-validation',
},
{ text: 'unregister', link: '/api/use-form-handler/unregister' },
{ text: 'values', link: '/api/use-form-handler/values' },
]
],
},
{ text: `FormHandler`, link: '/api/form-handler' }
]
}
{ text: `FormHandler`, link: '/api/form-handler' },
],
},
],
}
})
},
})
Loading