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

vue-validator-util

v0.3.2

Published

Vue.js mixin with utility methods for vue-validator.

Readme

vue-validator-util

Vue.js mixin with utility methods for vue-validator. Useful when using dynamic fields.

Install

npm install vue-validator-util

Usage

Within some Vue.js component:

JavaScript (ES6)

import Validation from 'vue-validator-util'

export default {
	data () {
		return {
			fields: [{
				name: 'some-field-name',
				label: 'My field label',
				value: null,
				validate: {
					required: {
						rule: true,
						message: 'The field is required'
					}
				}
			}]
		}
	},
	mixins: [
		Validation
	]
}

Template

<validator name="some-validator-name">
	<div v-for="field in fields" 
		class="form-group" 
		:class="{ 'has-error': hasValidationError(field.name, 'some-validator-name') }">
		
		<label :for="field.name">{{ field.label }}</label>
		<input type="text" class="form-control" 
			:id="field.name" 
			:field="field.name"
			v-model="field.value" 
			v-validate="field.validate" />
		
		<p class="help-block" v-for="msg in validationMessages(field.name, 'some-validator-name')">
			{{ msg }}
		</p>
	</div>
</validator>

Methods

getValidator([name])

Returns a vue-validator instance.

  • the default name value is $validation
  • the name is automatically transformed to camelCase and is also getting a $ prefix, so you can pass some-validator-name which will be translated to $someValidatorName

getValidatorField(fieldName, [validatorName])

Returns a vue-validator field.

  • the fieldName is automatically transformed to camelCase, so passing some-validator-field-name will get translated to someValidatorFieldName
  • the validatorName is passed to getValidator

hasValidationError(fieldName, [validatorName])

Check whether a vue-validator field is invalid. The field is considered invalid only when it's dirty and invalid properties are both true.

  • the fieldName is passed to getValidatorField
  • the validatorName is passed to getValidator

validationMessages(fieldName, [validatorName])

Returns messages for a vue-validator field.

  • the fieldName is passed to getValidatorField
  • the validatorName is passed to getValidator

firstValidationMessage(fieldName, [validatorName])

Returns the first message for a vue-validator field. Useful when trying to display a single message at a time.

  • the fieldName is passed to getValidatorField
  • the validatorName is passed to getValidator
Example

Assuming we have a field which is invalid for more than one rule (i.e. required and minlength), the following example will first display The field is required and after the required rule passes, it will display The field must have at least 10 characters..

data () {
	return {
		value: null,
		validate: {
			required: {
				rule: true,
				message: 'The field is required.'
			},
			minlength: {
				rule: 10,
				message: 'The field must have at least 10 characters.'
			}
		}
	}
}

Template:

<validator name="validation">
	<div class="form-group" 
		:class="{ 'has-error': hasValidationError('some-field-name') }">
		
		<label for="field-1">My label</label>
		<input type="text" class="form-control" 
			id="field-1" 
			field="some-field-name"
			v-model="value" 
			v-validate="validate" />
		
		<p class="help-block" v-if="hasValidationError('some-field-name')">
			{{ firstValidationMessage('some-field-name') }}
		</p>
	</div>
</validator>

--

Build

You can easily build vue-validator-util yourself.

Prerequisites

Our build tool of choice is Webpack. You should have webpack installed globally:

npm install -g webpack

And the build dependencies:

npm install

Build

Any of the following will create the file dist/vue-validator-util.js.

Production build

Includes minification and several optimizations:

npm run build

Development build

A faster build suited for development, with no optimizations and without minification:

npm run build-dev

Watch

Start an initial development build and then FAST continuous incremental builds:

npm run dev