« HOME

Datepicker in symfony with i18n

By Nacho Martín on 23 November 2009

Some time ago we decided in Makoondi that would be better to have one of these jquery calendars where the user picks the date:

datepicker

The first version was easy to implement with sfFormExtraPlugin , that implements sfWidgetFormJQueryDate.

$this->setWidget('available_from', new sfWidgetFormJQueryDate(array(
                        'image'=>'/images/icons/calendar.gif',
                        'culture' => sfContext::getInstance()->getUser()->getCulture(),
                        'format' => '%day%/%month%/%year%')
                       ));

You will need, apart from the plugin, some jquery files that you can download from the jquery-ui website:

jquery-ui-1.7.2.custom.min.js
jquery.datePicker.js

and, in order to use the i18n, you will need the localized version of jpicker from this website. e. g. the file with translations to Spanish would be:

jquery.datepick-es.js

But be aware! you will need to change mentions to $.datepick to $datepicker in that file in order to get it working!

$.datepicker.regional['es'] = {
...
$.datepicker.setDefaults($.datepicker.regional['es']);

otherwise you will get a “$.datepick is undefined” error :(

Written by @nacmartin

blog comments powered by Disqus

» ALL POSTS