Validity – jQuery Plugin and Agile Toolkit
I stumbled upon a interesting jQuery plugin called Validity. Syntax seemed straightforward so I decided to see how long it takes to integrate it into Agile Toolkit.
http://validity.thatscaptaintoyou.com/
See demo here: http://demo.atk4.com/validity.html
Set up
First – I needed a form. So I wrote a simple page for Agile Toolkit.
[php]
$f=$this->add(‘Form’);
$veh=$f->addField(‘line’,'veh’,'Number of Vehicles’);
$dob=$f->addField(‘line’,'birth’,'Date of birth’);
$f->addSubmit();
[/php]
Downloading
I was following documentation of Validity plugin and downloaded zip. I could have simply included the <script> and <style> includes into shared.html, but I decided to load them dynamically from the page (on demand)
[php]
$f->js(true)
->_load(‘jquery.validity.pack’)
->_css(‘jquery.validity’)
[/php]
$("#vehicles")
.require()
.match("number")
.range(4, 12);
$("#dob")
.require()
.match("date")
.lessThanOrEqualTo(new Date());
All this must be wrapped into a function and passed to: $(‘form’).validity( .. );
The equivalent code through PHP looks like this:
[php]
$f->validity(
$veh->js(null,
$dob->js()->require()->match(‘date’)->lessThanOrEqualTo($f->js(null,’new Date()’))
)->_enclose()->require()->match(‘number’)->range(4,12)
);
[/php]
Result
$f=$this->add(‘Form’);
$veh=$f->addField(‘line’,'veh’,'Number of Vehicles’);
$dob=$f->addField(‘line’,'birth’,'Date of birth’);
$f->addSubmit();
$f->js(true)
->_load(‘jquery.validity.pack’)
->_css(‘jquery.validity’)
->validity(
$veh->js(null,
$dob->js()->require()->match(‘date’)
->lessThanOrEqualTo($f->js(null,’new Date()’))
)->_enclose()->require()->match(‘number’)->range(4,12)
);
[/php]
I hope you will find this helpful.


This is helpful but IMO the JS code below is a mess. I don’t think its straight forward. Its not so easy to write it. Maybe we can develop this in a more logical fashion directly in Form_Field?