Neverending Package Mountain
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

jquery-validity

3.0.0 • Public • Published

jQuery Validity

A form validation jQuery plugin written in late 2015 (whatever that means).

This is heavily inspired by the Abide library (from the Zurb Foundation framework), but implemented completely from scratch and as a jQuery plugin, npm-ready and most of all not bloated.

Install

Using npm:

npm install jquery-validity

Browserify and others:

var $ = require('jquery')
require('jquery-validity')($)

ES2015 modules:

import $ from 'jquery'
import validity from 'jquery-validity'
 
validity($)

Usage

$('.my-form').validity(options)

Options

There are the defaults:

$.fn.validity.defaults = {
  attributeName: 'data-validators',
  errorClass: 'error',
  focusOnFirstError: true,
  onSubmit: null,
  parentSelector: 'p',
  requiredMessage: 'This field is required',
  timeout: 1000, // if `false`, no "live" validation
  validateOnBlur: true,
  validators: {}
}

Events

$form.on('validity.invalid', {
  fields,
  firstErrorField,
  form,
  submitEvent // original submit event
})
 
$form.on('validity.valid', {
  form,
  submitEvent
})

(TODO)

An example of an email validator function:

function emailValidator (message) {
  // A `validator` is a function that receives a `value`
  // and should return `null` if valid, or a message if not
  return function (value) {
    if (validator.isEmail(value)) {
      return null
    }
    return message
  }
}

TODO

  • Proper tests
  • Finish documentation
  • A better usage guide and examples

License

MIT

install

npm i jquery-validity

Downloadsweekly downloads

5

version

3.0.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability