# @formeus/vue

> Input state and validation manager library for Vue

Latest version **1.2.1** (published 2023-12-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install @formeus/vue
pnpm add @formeus/vue
yarn add @formeus/vue
bun add @formeus/vue
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.1 |
| Published | 2023-12-31 |
| First published | 2023-03-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 6.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | hala94 |
| Keywords | form, form validation, vue form |

## Links

- npm: https://www.npmjs.com/package/@formeus/vue
- npm.io page: https://npm.io/package/@formeus/vue

## Dependencies (1)

- [@formeus/core](https://npm.io/package/@formeus/core.md) 1.4.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.2.1 (latest) — 2023-12-31
- 1.2.0 — 2023-06-05
- 1.1.1 — 2023-04-07
- 1.1.0 — 2023-04-06
- 1.0.1 — 2023-03-14
- 1.0.0 — 2023-03-11

## README

# Formeus 🌀 Vue

Official Vue adapter for [Formeus](https://www.formeus.dev) library.

# Installation

```
yarn add @formeus/vue
npm install @formeus/vue
pnpm add @formeus/vue
```

# Key features

- designed to work with controlled components
- coordinated synchronous and asynchronous validations
- flexible validation times
- validation caching
- protected submit

# Minimal Example in Vue

```js
<script setup lang="ts">
import { useForm } from "@formeus/vue"

const { values, update } = useForm({
  initial: {
    username: "",
    password: "",
  },
})

function onSubmit() {
    api.signIn(values.username, value.password)
}
</script>

<template>
  <input
    :value="values.username"
    @input="(e) => update('username', (e.target as HTMLInputElement).value)"
  />
  <input
    :value="values.password"
    @input="(e) => update('password', (e.target as HTMLInputElement).value)"
  />
  <button @click="onSubmit">Submit</button>
</template>
```

# Advanced Example in Vue

```js
<script setup lang="ts">
import { useForm } from "@formeus/vue"

const { values, update, submit } = useForm({
  initial: {
    username: "",
    password: "",
  },
  validators: {
    username: ({ username }) =>
      username.length == 0
        ? new Error("Must contain at least 1 char.")
        : undefined,
    password: ({ password }) =>
      /^((?=\S*?[A-Z])(?=\S*?[a-z])(?=\S*?[0-9]).{5,})\S/.test(password)
        ? undefined
        : new Error("1 uppercase, 1 lowercase, 1 number and at least 6 chars."),
  },
  asyncValidators: {
    username: ({ username }, signal) => {
      // username is already client side validated here
      return api
        .checkUsernameAvailable(username, signal)
        .then((isAvailable) =>
          isAvailable ? undefined : new Error("username not available")
        )
    },
  },
  onSubmitForm: ({ username, password }) => {
    api.signIn(username, password)
  },
})

function onSubmit() {
  submit.value()
}
</script>

<template>
  <input
    :value="values.username"
    @input="(e) => update('username', (e.target as HTMLInputElement).value)"
  />
  <input
    :value="values.password"
    @input="(e) => update('password', (e.target as HTMLInputElement).value)"
  />
  <button @click="onSubmit">Submit</button>
</template>
```

---
_Source: https://npm.io/package/@formeus/vue · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
