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

vueform

v2.0.0

Published

Form validation for Vue.js powered by HTML5

Downloads

354

Readme

vueform

Form validation for Vue.js powered by HTML5

Build status

Features

  • Easy: integrates with Vue.js to provide a reactive interface for working with validity state.
  • Lightweight: uses the HTML5 validation API whenever possible.
  • Flexible: allows you to set the validity state within your own custom validators.
  • Convenient: adds a configurable .wasSubmitted class to your forms when they are submitted and .wasFocused class to your fields when they are focused so that you're able to have more control when styling invalid fields with the :invalid psuedo-class.

Instructions

  1. Install vueform:

    npm install vueform --save
  2. Tell Vue.js to use vueform and then create a new form in your component data hook:

    import Vue from 'vue'
    import VueForm from 'vueform'
    
    Vue.use(VueForm)
    
    //...
    data() {
      return {
        contactForm: new VueForm()
      }
    }
    //...
  3. Pass the form object to vueform with the v-form directive:

    <form v-form="contactForm">
    <!-- ... -->
    </form>
  4. Add a form field to the form. Make sure it has an id property so that it can be identified:

    <label for="name">Name:</label>
    <input type="text" id="name" v-model="contactData.name" required>

    Note: When you're grouping radio buttons or checkboxes by the same name property and you want to validate that the group has a value (i.e. one of the elements is checked), simply pass the name of the group to the VueForm instance in the required array:

    const reasons = { name: 'reasons', required: () => isReasonsRequired }
    patientForm: new VueForm({ required: ['sex', reasons] })
  5. By default, your form will be set to noValidate which tells the browser to slow it's roll and gives you more control over the validation process. This means the browser won't show validation error messages. You can either display your own validation error messages, for example:

    <div v-if="contactForm.$wasSubmitted" class="colorRed">
      <div v-if="contactForm.name.valueMissing">
        Name is required.
      </div>
      <div v-if="contactForm.name.patternMismatch">
        Please use only letters, spaces, dashes, and apostrophes.
      </div>
    </div>

    Or disable noValidate so that the browser displays validation error messages, by passing the noValidate: false option when creating your form, for example:

    contactForm: new VueForm({ noValidate: false })

API

VueForm constructor options (with default values):

{
  wasFocusedClass: `wasFocused`
  wasSubmittedClass: `wasSubmitted`
  noValidate: true,
  ignoredFields: [],
  requiredGroups: [],
  customValidators: {}
}

VueForm.state properties:

| Property | Type | Description | |------------------|---------|------------------------------------------| | wasSubmitted | Boolean | True if the form was submitted. | | isInvalid | Boolean | True if the form is invalid. | | isValid | Boolean | True if the form is valid. | | invalidFields | Array | A collection of names of invalid fields. | | fields | Object | A map of |

VueForm methods:

| Method | Parameters | Description | |----------------------|------------|---------------------------------------| | $setCustomValidity | field: String, invalid: Boolean or String | A convenience wrapper for element.setCustomValidity(). Useful when updating the validity of a field based on a custom validator. |