Skip to content
This repository was archived by the owner on Apr 9, 2025. It is now read-only.
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
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +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)
104 changes: 95 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,102 @@
# Vue 3 + TypeScript + Vite

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.
<div align="center">
<h1>vue-form-handler</h1>

## Recommended IDE Setup
The easy way of handling your vue forms
</div>

- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar)
[![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)
[![version](https://img.shields.io/npm/v/deep-object-diff.svg?style=flat-square)](https://www.npmjs.com/package/deep-object-diff)
[![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)
[![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)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)

## Type Support For `.vue` Imports in TS
## 📦 Installation
---
``` yarn add vue-form-handler ```

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:
``` npm i --save vue-form-handler ```

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.
2. Reload the VS Code window by running `Developer: Reload Window` from the command palette.
## 🚀 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

You can learn more about Take Over mode [here](https://github.com/johnsoncodehk/volar/discussions/471).
## 🦄 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>
</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>
```

### 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>
</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>
```

### 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>
</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>
```

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

## 💜 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)
29 changes: 25 additions & 4 deletions docs/.vitepress/config.cts
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import { defineConfig } from "vitepress"

export default defineConfig({
title: 'Vue form handler',
title: 'VueFormHandler',
description: 'Discover the easy way of handling your vue forms',
themeConfig: {
logo: '/favicon.svg',
editLink: {
pattern: 'https://github.com/dbssman/vue-form-handler/edit/master/docs/:path',
text: 'Edit this page on GitHub',
},
nav: [
{ text: 'Home', link: '/' },
{ text: 'Get started', link: '/getting-started' },
{ text: 'Get started', link: '/get-started' },
],
sidebar: [
{
text: 'Documentation', items: [
{ text: 'Get started', link: '/getting-started' },
{ text: 'Get started', link: '/get-started' },
{ text: 'Tutorial', link: '/tutorial' },
{
text: 'Guides', items: [
Expand All @@ -36,7 +41,23 @@ export default defineConfig({
},
{
text: 'API Reference', items: [
{ text: 'useFormHandler()', link: '/api/use-form-handler' },
{
text: 'useFormHandler', link: '/api/use-form-handler/index', 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: '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: 'unregister', link: '/api/use-form-handler/unregister' },
{ text: 'values', link: '/api/use-form-handler/values' },
]
},
{ text: `FormHandler`, link: '/api/form-handler' }
]
}
Expand Down
1 change: 1 addition & 0 deletions docs/api/use-form-handler/clear-error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# clearError
1 change: 1 addition & 0 deletions docs/api/use-form-handler/clear-field.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# clearField
1 change: 1 addition & 0 deletions docs/api/use-form-handler/form-state.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# formState
1 change: 1 addition & 0 deletions docs/api/use-form-handler/handle-submit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# handleSubmit
1 change: 1 addition & 0 deletions docs/api/use-form-handler/modified-values.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# modifiedValues
1 change: 1 addition & 0 deletions docs/api/use-form-handler/register.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# register
1 change: 1 addition & 0 deletions docs/api/use-form-handler/reset-field.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# resetField
1 change: 1 addition & 0 deletions docs/api/use-form-handler/reset-form.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# resetForm
1 change: 1 addition & 0 deletions docs/api/use-form-handler/set-error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# setError
1 change: 1 addition & 0 deletions docs/api/use-form-handler/set-value.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# setValue
1 change: 1 addition & 0 deletions docs/api/use-form-handler/trigger-validation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# triggerValidation
1 change: 1 addition & 0 deletions docs/api/use-form-handler/unregister.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# unregister
1 change: 1 addition & 0 deletions docs/api/use-form-handler/values.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# values
53 changes: 53 additions & 0 deletions docs/get-started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Get started

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.

Here is a minimal example:

```vue
<template>
<form @submit.prevent="handleSubmit(successFn)">
<input v-bind="register('firstName')" />
<input v-bind="register('lastName')" />
<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>
```

**Result**

- Interactive demo here

The above example shows how easy it is to use this solution, you simply have to register your components by giving them a name (something you'd need to do)

## Motivation

I [@dbssman](https://github.com/dbssman) wrote VueFormHandler due to the need of an abstract, flexible and reliable form handler where you could keep the components you already had, solutions like these are available for React, but there was none for vue until now.

## Installation

You can install VueFormHandler

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

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

## Why not... ?

There are some form solutions for vue 3 ([VueForm](https://vueform.com/), [FormKit](https://formkit.com/)), but you're forced to use the built-in components they provide, and you don't have enough control over the form itself that, for some approaches would be interesting.


## Influences

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)
31 changes: 0 additions & 31 deletions docs/getting-started.md

This file was deleted.

18 changes: 9 additions & 9 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@
layout: home

hero:
name: Vue form handler
name: VueFormHandler
text: Vue & TS powered form handler.
tagline: The only handler you'll need to easily work with forms in vue
image:
src: /logo.png
alt: Vue form handler
src: /favicon.svg
alt: VueFormHandler
actions:
- theme: brand
text: Get Started
link: /getting-started
link: /get-started
- theme: alt
text: View on GitHub
link: https://github.com/dbssman/vue-form-handler

features:
- title: Fully tree shakeable
details: Only take what you want
icon:
- title: Performant
details: Great performance even with big and complex forms
icon: 🏎
- title: Type Strong
details: Written in TypeScript, with full TS docs
icon: 💪
- title: Flexible
details: You can wrap the handler over native inputs or any other like the ones from material libraries or custom inputs
details: Use on top of native inputs, custom inputs or material libraries!
icon: 🔩
- title: Super light
details: Small package size
Expand All @@ -33,6 +33,6 @@ features:
details: Great development experience
icon: 💻
- title: Interactive demos
details: Documentation of functions also come with interactive demos!
details: Coming soon...
icon: 🎪
---
Binary file added docs/public/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/public/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/public/favicon.ico
Binary file not shown.
13 changes: 13 additions & 0 deletions docs/public/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading