• Stars
    star
    141
  • Rank 259,971 (Top 6 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 4 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Building forms with vue composition API.

Vue Hooks Form Β· license build status Coverage Status

Building forms with Vue composition API.

The API is not stable and might change in the future.

Docs

Visit https://beizhedenglong.github.io/vue-hooks-form/.

Installation

  yarn add vue-hooks-form

Features

  • UI decoupling: Since It does not contain any UI code, It can be easily integrated with other UI libraries.
  • Easy to adoptable: Since form state is inherently local and ephemeral, it can be easily adopted.
  • Easy to use: No fancy stuffs, just reactive values/errors.
  • TypeScript support.

Quickstart

<template>
  <form @submit="onSubmit">
    <label>Username</label>
    <input v-model="username.value" :ref="username.ref" />
    <p v-if="username.error">{{ username.error.message }}</p>
    <label>Password</label>
    <input v-model="password.value" :ref="password.ref" type="password" />
    <p v-if="password.error">{{ password.error.message }}</p>
    <button type="submit">submit</button>
  </form>
</template>

<script>
import { useForm } from 'vue-hooks-form'

export default {
  setup() {
    const { useField, handleSubmit } = useForm({
      defaultValues: {},
    })
    const username = useField('username', {
      rule: { required: true },
    })
    const password = useField('password', {
      rule: {
        required: true,
        min: 6,
        max: 10,
      },
    })
    const onSubmit = (data) => console.log(data)
    return {
      username,
      password,
      onSubmit: handleSubmit(onSubmit),
    }
  },
}
</script>

Live Demo

Edit Vue Hooks Form Demo

API(TODO)

useForm

const {
  values,
  getFieldValues,
  errors,
  validateFields,
  validateField,
  get,
  set,
  useField,
  handleSubmit
} = useForm({
  defaultValues: {},
  shouldUnregister: true,
  validateMode: 'change',
})

useField

const {
 ref,
 value,
 error,
 validate
} = useField(path, options)

Credits

This project was inspired by react-hook-form, formik, and many other form libraries.

More Repositories

1

rough-charts

πŸ“ˆ A responsive, composable react charting library with a hand-drawn style.
TypeScript
1,516
star
2

weird-fonts

𝑨 π‘±π’‚π’—π’‚π‘Ίπ’„π’“π’Šπ’‘π’• π’‘π’‚π’„π’Œπ’‚π’ˆπ’† 𝒕𝒉𝒂𝒕 𝒕𝒖𝒓𝒏 π’‚π’π’‘π’‰π’‚π’π’–π’Žπ’†π’“π’Šπ’„ 𝒄𝒉𝒂𝒓𝒂𝒄𝒕𝒆𝒓𝒔 π’Šπ’π’•π’ π’˜π’†π’Šπ’“π’… 𝒇𝒐𝒏𝒕 π’”π’•π’šπ’π’†.
TypeScript
609
star
3

react-hooks-lib

A set of reusable React Hooks.
JavaScript
540
star
4

leetcode-site-generator

Generate your personal LeetCode website with one command!
JavaScript
103
star
5

reactablejs

A react high-order component for interact.js(drag and drop, resizing and multi-touch gestures).
TypeScript
62
star
6

react-multi-crops

A multiple cropping component for React
JavaScript
40
star
7

reason-hooks-lib

A set of reusable ReasonReact hooks.
Reason
32
star
8

reason-hooks-testing-library

ReasonML bindings for react-hooks-testing-library
Reason
25
star
9

reason-unstated

A simple reason react state management library that help you share hook state and logic easily.
OCaml
15
star
10

chrome-extension-starter-kit

Chrome Extension Starter Kit
JavaScript
13
star
11

reason-powerplug

πŸ”Œ Renderless Containers For ReasonReact
OCaml
11
star
12

nqm

npm with query
JavaScript
8
star
13

hooks-to-others

Transform react hooks into render props and high-order component patterns.
TypeScript
4
star
14

bookmark-search

A Chrome extension for searching bookmark quickly.
JavaScript
4
star
15

mac-look-up-log

Look up workflow for macOS
3
star
16

redux-and-react-redux

Simple Redux and React Redux implementation
JavaScript
3
star
17

js-lens

Safely accessing and updating nested object with functional features.
TypeScript
3
star
18

vue-reactivity

JavaScript
2
star
19

fusuma-imgs

1
star
20

mini-context-store

A react state management library using new context api
JavaScript
1
star
21

leetcode-solutions

Victor's LeetCode Website.
JavaScript
1
star
22

gatsby-starter-gcn

JavaScript
1
star
23

ant-design-snippets

An ant design snippets extension for VS Code.
1
star
24

safety-redux

Query and mutate Redux state safely.
JavaScript
1
star
25

beizhedenglong.github.io

beizhedenglong.github.io
HTML
1
star
26

rc-value

Make React component switch between Controlled Component and Uncontrolled Component easily.
JavaScript
1
star