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

vue-coe-validator

v0.4.3

Published

validator

Downloads

17

Readme

Install

yarn add vue-coe-validator

Include Plugin

import Vue from 'vue'

import { validator } from 'vue-coe-validator'

Vue.use(validator)

Include Mixin (required only on components that need validation)

import { formSetup } from 'vue-coe-validator'

mixins: [ formSetup ]

Pay attention:

Be careful not to create a state with the name: validations and messages.

These names are reserved for the library and overwriting them may compromise their behavior.

How to use

<template>
  <section>
    <form name="form1">
      <c-input
        name="input1"
        :validation="$hasError('input1')"
        v-model="form1.input1"
      />

      <c-input
        name="input2"
        :validation="$hasError('input2')"
        v-model="form1.input2"
      />

      <c-input
        name="input3"
        :validation="$hasError('input3')"
        v-model="form1.input3"
      />
    </form>

    <form name="form2">
      <c-input
        name="input1"
        :validation="$hasError('input1', 'form2')"
        v-model="form2.input1"
      />
    </form>
  </section>
</template>

<script>
import { formSetup } from 'vue-coe-validator'

export default {
  mixins: [ formSetup ],

  data () {
    return {
      form1: { input1: '', input2: '22' },
      form2: { input1: '33' }
    }
  },

  validation: {
    form1: {
      input1: {
        required: true,
        alphabetic: true
      },
      input2: {
        required: true,
        pattern: /^[A-Z0-9_'%=+!`#~$*?^{}&|-]+([.][A-Z0-9_'%=+!`#~$*?^{}&|-]+)*@[A-Z0-9-]+(\.[A-Z0-9-]+)+$/i
      },
      input3: {
        required: true
      }
    },
    form2: {
      input1: {
        required: true,
        alpha: true
      }
    }
  },

  messages: {
    form1: {
      input1: {
        required: 'não pode ser vazio!',
        alphabetic: 'tá errado, é alphabetic!'
      },
      input2: {
        required: 'preenche tudo!',
        pattern: 'precisa ser e-mail!'
      }
    },
    form2: {
      input1: {
        required: 'tá vazio, não pode!'
      }
    }
  }
}
</script>

You can also define validations with directives

<c-input
  name="name"
  :validation="$hasError('name')"
  v-validator="{ required: true }"
  v-model="form1.name"
/>

Or programmatically, using $validator.add

methods: {
  addField () {
    // add new field
    this.form1 = {
      ...this.form1,
      coe: 'mané'
    }

    // create validation for new field
    const validations = {
      coe: { required: true }
    }

    // set validation for new field
    this.$validator.add(validations, 'form1')
  }
}

Rules

Name | required | About ----- | ------- | ----- form | true | set an name for the scope of the form input | true | name the input with the tag name and its respective form value

Mixin methods

Name | Params | About :-----------|:--------------------------------:|:----------- $hasError | (inputName[str], formName[str])| returns a boolean

*formName: required only when you have more than one form

Validator methods

Name | Params | About :--------------|:----------------------------------:|:-------------------- add | (validations[obj], formName[str])| set validation for new field touch | (inputName[str], formName[str]) | touches a field (isTouched = true) resetField | (formName[str]) | resets a field resetForm | (formName[str]) | resets a form validateField | (formName[str]) | touches a field and checks if it is valid validateForm | (formName[str]) | touch the form fields and check if it is valid isFormValid | (formName[str]) | promise that returns a boolean

*formName: required only when you have more than one form

Customize validation messages globally

import { validator } from 'vue-coe-validator'

Vue.use(validator, {
  messages: {
    required: 'must be filled',
    alpha: 'must be alpha'
  }
})

Set validate on blur

import { validator } from 'vue-coe-validator'

Vue.use(validator, { 
  validateOnBlur: true // default is false 
})

Validations

{
  alphabetic: true
}
{
  alpha: true
}
{
  pattern: /^[A-Z0-9_'%=+!`#~$*?^{}&|-]+([.][A-Z0-9_'%=+!`#~$*?^{}&|-]+)*@[A-Z0-9-]+(\.[A-Z0-9-]+)+$/i  
}
{
  numeric: true
}
{
  required: true
}
{
  custom: [
    (value) => value === '123',
    (value) => typeof value === 'string'
  ]
}
{
  customAsync: [
    value => new Promise(resolve => setTimeout(() => {
      resolve(value === '[email protected]')
    }, 2000)),
    value => new Promise(resolve => setTimeout(() => {
      resolve(typeof value === 'string')
    }, 3000))
  ]
}