npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@lockvoid/vue-form

v0.1.4

Published

[![CI](https://github.com/lockvoid/vue-form/actions/workflows/test.yml/badge.svg)](https://github.com/lockvoid/vue-form/actions/workflows/test.yml) [![npm version](https://badge.fury.io/js/@lockvoid%2Fvue-form.svg)](https://badge.fury.io/js/@lockvoid%2Fvu

Readme

@lockvoid/vue-form

CI npm version Coverage Bundlephobia License: MIT

Tiny, fast, Vue 3 form composable with stable bindings and Valibot validation.

  • 1 kB gzipped
  • Zero components, just a composable
  • Works with any input (native or custom) via a simple binding shape
  • Validation modes: "change", "blur" and "submit"
  • Easy to unit/integration test

Installation

npm i @lockvoid/vue-form valibot

valibot is a peer dependency.

Quick start

<script setup lang="ts">
import { useForm } from '@lockvoid/vue-form'
import * as v from 'valibot'

const schema = v.pipe(
  v.object({
    email: v.pipe(v.string(), v.email()),
  })
)

const form = useForm({
  schema,

  validationMode: 'change',

  async onSubmit({ email }) {
    await api.createUser({ email })
  },
})
</script>

<template>
  <form @submit.prevent="form.submit">
    <input v-bind="form.bind('email')" placeholder="Email" />

    <button type="submit" :disabled="form.isInvalid.value">
      Submit
    </button>

    <p v-if="form.errors.email">
      {{ form.errors.email }}
    </p>
  </form>
</template>

Concepts

Stable bindings

form.bind('field') returns the same object instance across renders with modelValue, event handlers (onUpdate:modelValue, onInput, onChange), and a name property. This avoids unnecessary prop/listener diffs in child inputs.

You can use it with:

  • native <input> (uses onInput)
  • custom components using v-model (uses onUpdate:modelValue)
  • or onChange-style components

Validation modes

  • "change": validates on every change and updates errors live.
  • "submit" (default): UI stays neutral until the first submit. After the first submit, errors are computed and validation switches to change mode.
  • "blur": validates only when input loses focus (blur event). UI stays neutral until first blur.

API

useForm(options)

Options

| Property | Type | Default | Description | |----------|------|---------|-------------| | schema | Valibot schema | required | Validation schema | | initialValues | Record<string, any> | {} | Initial form values | | validationMode | 'change' \| 'submit' \| 'blur' | 'submit' | When to validate | | onSubmit | (values) => void \| Promise<void> | required | Submit handler |

Returns

| Property | Type | Description | |----------|------|-------------| | bind(name) | Binding | Get stable binding for field | | submit() | Promise<void> | Submit the form | | isInvalid | Ref<boolean> | Form validation state | | isSubmitting | Ref<boolean> | Submission loading state | | values | Record<string, any> | Current form values | | errors | Record<string, string> | Validation errors |

Binding

Each form.bind('field') returns an object with:

  • modelValue - current field value (for Vue components)
  • value - current field value (for native HTML inputs)
  • onUpdate:modelValue - v-model handler
  • onInput / onChange - input event handlers
  • onBlur - blur event handler (for blur validation mode)
  • name - field name

Examples

Custom input component

<!-- MyInput.vue -->
<script setup>
const modelValue = defineModel()
</script>

<template>
  <input :value="modelValue" @input="modelValue = $event.target.value" />
</template>
<MyInput v-bind="form.bind('email')" />

Rendering errors

<p v-if="form.errors.email" class="text-red-500">
  {{ form.errors.email }}
</p>
  • In "change" mode: errors appear as you type.
  • In "submit" mode: errors appear only after submit() is attempted, then validation switches to change mode.
  • In "blur" mode: errors appear only after input loses focus.

Loading state

<button type="submit" :disabled="form.isInvalid.value">
  <span v-if="form.isSubmitting.value">
    Loading…
  </span>

  <span v-else>
    Submit
  </span>
</button>

Testing

Unit (no DOM)

Drive the composable in an effectScope, without mounting components.

import { effectScope, nextTick, unref } from 'vue'
import { describe, it, expect, vi } from 'vitest'
import * as v from 'valibot'
import { useForm } from '@lockvoid/vue-form'

const schema = v.pipe(v.object({ email: v.pipe(v.string(), v.email()) }))

describe('useForm', () => {
  it('validates and submits', async () => {
    // 1. Setup form with change validation
    const onSubmit = vi.fn()

    const scope = effectScope()

    const form = scope.run(() =>
      useForm({ schema, validationMode: 'change', onSubmit })
    )!

    // 2. Enter valid email
    const emailBinding = form.bind('email')

    emailBinding['onUpdate:modelValue']('[email protected]')

    await nextTick()

    // 3. Verify form becomes valid
    expect(unref(form.isInvalid)).toBe(false)

    // 4. Submit form
    await form.submit()

    // 5. Verify onSubmit was called with correct values
    expect(onSubmit).toHaveBeenCalledWith({ email: '[email protected]' })

    // 6. Cleanup
    scope.stop()
  })
})

Integration (mount)

import { mount } from '@vue/test-utils'
import { defineComponent, nextTick } from 'vue'
import * as v from 'valibot'
import { useForm } from '@lockvoid/vue-form'

const Host = defineComponent({
  setup(_, { emit }) {
    const schema = v.pipe(v.object({ email: v.pipe(v.string(), v.email()) }))

    const form = useForm({ schema, validationMode: 'change', onSubmit: (values) => emit('success', values) })

    return { form };
  },

  template: `
    <form @submit.prevent="form.submit">
      <input v-bind="form.bind('email')" data-testid="email" />

      <button data-testid="submit" :disabled="form.isInvalid.value">
        Submit
      </button>
    </form>
  `,
})

it('enables submit when valid', async () => {
  const wrapper = mount(Host)

  await wrapper.get('[data-testid="email"]').setValue('[email protected]')

  await nextTick()

  expect(wrapper.get('[data-testid="submit"]').attributes('disabled')).toBeUndefined()
})

License

MIT © LockVoid Labs ~●~

Trigger CI