Drupal module that provides integration with the client side validation library
parsley.js.
Currently this module only integrates on the FAPI layer.

This is not an end-user module yet, each form has to declare that they want to have parsley.js validate their form.

At its core it simply injects the correct attributes into the relevant FAPI field using hook_form_alter.
It expects the same syntax as FAPI validation module using the #rules attribute.

You can find more details on parsleyjs.org

Requirements

  1. Libraries module
  2. Parsley.js 2.0.7
  3. jQuery Update

Installation

  1. Download the parsley.js library https://github.com/guillaumepotier/Parsley.js/archive/2.0.7.tar.gz to your libraries location (usually sites/all/libraries)
  2. Expand the contents of the archive in to parsley, so that the path to parsley.js reads sites/all/libraries/parsley/dist/parsley.min.js
  3. Enable the module under admin/modules
  4. Set jQuery update to 1.8 or later under admin/config/development/jquery_update

Configuration

Currently there are no configuration options

Usage

To enable a form to be validated, simply set #parsley_js in the form array to true.

$form['#parsley'] = TRUE;

Set the #parsley_rules key on each field you want validated


$form['my-field'] = array(
  '#title' => t('My Field'),
  '#description' => t("It's my field, only I get to fill it in"),
  '#required' => TRUE,
  '#parsley_rules' => array(
    'length[3,10]',
    'email'
  ),
);

Rules

Currently only the following rules are implemented.

  • notblank
  • email
  • url
  • urlstrict
  • digit
  • numeric
  • alpha_numeric
  • date_iso
  • phone
  • length/minlength
  • range

Details of these rules can be found at Parlsey.js validators

Exceptions

dateIso:
Parsley.js calls it dateIso, use date_iso instead to keep consistency

length:
The length rules supports both specific length and min length.
A set length is indicated by length[2,9] meaning any string between 2 and 9 characters long
A min length is indicated by length[3, *]

range:
The range follows the same syntax, except this checks the numeric length of the
value. range[3, 8] validates the input is between 3 and 8

Todo

  • Automated Tests
  • Admin form for site builders to choose other forms
  • Webform integration

Project information

Releases