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 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue3-form

v1.2.8

Published

A form validation plugin for vue 3 and/or composition api

Downloads

68

Readme

vue3-form

This package offers form validation using vue 3 composition api

Installation

npm install vue3-form

Usage

<template>
  <form @submit.prevent="submit">
    <input v-model="form.fields.email.value" type="email" placeholder="Enter your email address" />

    <!-- Display error message -->
    <p>{{ form.fields.email.errors.required }}</p>
    <p>{{ form.fields.email.errors.email }}</p>
    <!-- OR -->
    <p>
      {{ getFieldError(form.fields.email).join(', ') }}
    </p>


    <input v-model="form.fields.password.value" type="password" placeholder="Enter your password" />

    <!-- Display error message -->
    <p>{{ form.fields.password.errors.required }}</p>
    <p>{{ form.fields.password.errors.stringMin }}</p>
    <!-- OR -->
    <p>
      {{ getFieldError(form.fields.password, 'stringMax') }}
    </p>
    <!-- OR -->
    <p>
      {{ getFieldError(form.fields.password).join(', ') }}
    </p>

    <button type="submit">
      Login
    </button>
  </form>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import { getFieldError, getRawFormData, useForm, validateForm } from 'vue3-form';

export default defineComponent({
  setup() {
    const form = useForm({
      email: { rules: ['required', 'email'] },
      password: {
        rules: [
          'required',
          'stringMin:8',
          'stringMax:32',
          'alphabetsLowercase',
          'alphabetsUppercase',
          'numbers',
          'specialCharacters',
          'noSequence',
        ]
      }
    });

    const submit = () => {
      if (!validateForm(form)) {
        // Form is invalid
        return;
      }

      // Form is valid...
      // proceed with submission.
      const fields = getRawFormData(form);
    }
    
    return { form, getFieldError, submit };
  },
});
</script>

Form instance structure

{
  fields: Record<string, FormField>
  error: string | null
  success: string | null
  loading: boolean
  touched: boolean
  valid: boolean
}

Form field instance structure

{
  name: string
  value: any
  rules: string[]
  errors: Record<string, string>
  serverErrors: string[]
}

Available methods

useForm

Generates a new form instance.

getFields

Returns an array of all the fields in the form.

getFormData

Creates and returns a FormData instance using the fields of the form.

getRawFormData

Get a json object of the form using the field names as keys.

updateForm

Updates the states and properties of the form.

setFormErrors

Updates the errors of the fields in the form.

getFieldError

Returns either a single error or all errors of the field specified.

validateField

Checks and returns a fields validity.

validateForm

Checks and returns the validity of the specified form by validating all it's fields.

resetForm

Returns a form to it's initial state, including it's fields, and states.

Available validation rules

  • alphabets
  • alphabetsLowercase
  • alphabetsLowercaseOnly
  • alphabetsOnly
  • alphabetsUppercase
  • alphabetsUppercaseOnly
  • array
  • arrayContains
  • arrayContains:string
  • arrayDoesntContain
  • arrayDoesntContain:string
  • boolean
  • date
  • dateAfter
  • dateAfter:string
  • dateBefore
  • dateBefore:string
  • dateBetween
  • dateBetween:string
  • dateExact
  • dateExact:string
  • dateFormat
  • dateFormat:string
  • different
  • email
  • exact
  • exact:string
  • false
  • file
  • files
  • filesLength
  • filesMax
  • filesMin
  • money
  • name
  • noSequence
  • nullable
  • numberBetween
  • numberBetween:number,${number}
  • numberExact
  • numberExact:number
  • numberMax
  • numberMax:number
  • numberMin
  • numberMin:number
  • numbers
  • numbersOnly
  • phone
  • required
  • specialCharacters
  • specialCharactersOnly
  • stringLength
  • stringLength:number
  • stringMax
  • stringMax:number
  • stringMin
  • stringMin:number
  • true
  • url