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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@aaronsuuu/vue-zod-form

v1.0.2

Published

A Vue 3 library for zod form validation

Readme

vue-zod-form

vue-zod-form is a form validation tool based on Vue and Zod, designed to simplify the form validation process and provide an efficient and extensible solution.

Features

  • Zod-based Validation: Use Zod to define and validate form data structures.
  • Easy to Use: Seamlessly integrates with Vue, offering an intuitive API.
  • High Performance: Lightweight design suitable for applications of all sizes.
  • Extensibility: Supports custom validation rules and error handling.

Installation

Install using npm or yarn:

npm install vue-zod-form
# or
yarn add vue-zod-form

Quick Start

Here is a simple example demonstrating how to use vue-zod-form for form validation:

<template>
  <form @submit.prevent="onSubmit">
    <input v-model="form.name.value" placeholder="Name" />
    <span v-if="form.name.error">{{ form.name.error.message }}</span>

    <input v-model="form.age.value" placeholder="Age" type="number" />
    <span v-if="form.age.error">{{ form.age.error.message }}</span>

    <input v-model="form.email.value" placeholder="Email" />
    <span v-if="form.email.error">{{ form.email.error.message }}</span>

    <button type="submit">Submit</button>
    <button type="button" @click="clearAll">Clear All</button>
  </form>
</template>

<script setup>
import { useZodForm } from 'vue-zod-form';
import { z } from 'zod';

// form is a reactive object containing the form data and error information, using it to bind to the input fields.
const { form, validate, clearOne, clearAll } = useZodForm(
  {
    name: {
      value: '',
      schema: z.string().min(3, { message: 'Name must be at least 3 characters long' }),
    },
    age: {
      value: '',
      schema: z.number().min(18, { message: 'You must be at least 18 years old' }),
    },
    email: {
      value: '',
      schema: z.string().email({ message: 'Invalid email address' }),
    },
  }
);

const onSubmit = () => {
  try{
    validate();
    // If validation passes, you can proceed with form submission
    console.log('Form submitted successfully:', {
      name: form.name.value,
      age: form.age.value,
      email: form.email.value,
    });
  }catch(e){
    console.error(e);
    // If validation fails, you can handle the errors here, and error message will be placed in the respective fields
    // For example, you can show a notification or highlight the invalid fields
    // You might also want to log the error details for debugging purposes
  }
};
</script>

Safe Mode

In safe mode, the validation result will not throw an error if the validation fails. Instead, it will return an object containing the validation results for each field. This allows you to handle validation errors more flexibly.

Example of Safe Mode

const initialData = {
  name: {
    value: '',
    schema: z.string().min(3, { message: 'Name must be at least 3 characters long' }),
  },
  age: {
    value: '',
    schema: z.number().min(18, { message: 'You must be at least 18 years old' }),
  },
  email: {
    value: '',
    schema: z.string().email({ message: 'Invalid email address' }),
  },
}

// Using safe mode to validate the form
const { form, validate } = useZodForm(initialData, { safe: true });

function onSubmit(){
  const result = validate();
  if(result.success){
    // If validation passes, you can proceed with form submission
    console.log('Form submitted successfully:', {
      name: form.name.value,
      age: form.age.value,
      email: form.email.value,
    });
  }
}

API

useZodForm(schema, options?)

  • Parameters:
    • schema: Validation schema defined using Zod.
    • options (optional): Configuration options, e.g., { safe: true } to enable safe mode for validation results.
  • Returns:
    • form: Reactive form data and error information.
    • validate: Validation method, supports full form or single field validation.
    • clearOne: Clears the value and error of a specific field.
    • clearAll: Clears the values and errors of all fields.