jQuery is in my opinion the best javascript library. The Zend Framework guys recently decided to partner with dojo, which is ok but that isn’t my personal choice.
This doesn’t mean though that you can’t use another library, it will just require a little effort on your part. jQuery also makes a UI library that can be integrated into the Zend Framework using View Helpers.
class View_Helper_FormDate extends Zend_View_Helper_FormText
{
public function formDate($name, $value = null, $attribs = null)
{
// Change the next two lines to the apropriate location
$this->view->headLink()->appendStylesheet('/css/ui.datepicker.css');
$this->view->headScript()->appendFile('/scripts/ui.datepicker.js');
$date = new Zend_Date($value);
$value = $date->toString('d.M.y');
$attribs['onkeydown'] = 'return false;';
$attribs['id'] = str_replace(']', '', str_replace('[', '-', $name));
// This puts the script in place to turn the form element
// into a datepicker.
$this->view->headScript()->appendScript(
"$(document).ready(function()
{ $('#" . $attribs['id'] . "').datepicker({dateFormat: 'd.m.yy'}); } );");
return parent::formText($name, $value, $attribs);
}
}
// From inside a view
$this->formDate('date', $model->date);
This code does require that you use the view helpers headLink() and headScript() to include the needed CSS and JS files. This method is also locale unaware, but that can be added.
Zend Framework also provides a Zend_Form. The elements of Zend_Form simply use View_Helpers to generate the HTML of these elements. There may be a possibility to integrate these but I’m not completely sure on that.
Photos
RSS Feed
Won’t this include the css and datepicker js files once for every date picker element you put on your page?
No, the Zend Framework has built in functionality to check for double inclusions.