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
- Libraries module
- Parsley.js 2.0.7
- jQuery Update
Installation
- 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)
- Expand the contents of the archive in to
parsley
, so that the path to parsley.js readssites/all/libraries/parsley/dist/parsley.min.js
- Enable the module under admin/modules
- 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
- 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
- Module categories: Content Display, Developer Tools
- 15 sites report using this module
- Created by Botto on , updated
- Stable releases for this project are covered by the security advisory policy.
Look for the shield icon below.
Releases
Development version: 7.x-2.x-dev updated 16 Mar 2015 at 14:58 UTC
Development version: 7.x-1.x-dev updated 7 Feb 2015 at 15:33 UTC