Javascript calendar widget for filters
This is a quick way to have a javascript calendar instead of the nasty
3 selects (y/m/d) for every date filter:
1. install sfFormExtraPlugin
2. generate admin backend as usual
3. put the following code in lib/filter/doctrine/BaseFormFilterDoctrine.class.php:
abstract class BaseFormFilterDoctrine extends sfFormFilterDoctrine
{
public function setup()
{
foreach ($this->widgetSchema->getFields() as $name => $widget) {
if ($widget instanceof sfWidgetFormFilterDate) {
$this->setWidget($name, new sfWidgetFormJQueryDate(array(
'image'=>'/images/calendar.gif',
'format' => '%day%/%month%/%year%'
)));
}
}
}
}
2 comments:
could you please put a screenshot?
Your code changes the date range selector to one date.
I made some corrections to make it work:
public function setup() {
foreach ($this->widgetSchema->getFields() as $name => $widget) {
if ($widget instanceof sfWidgetFormFilterDate) {
$from = $widget->getOption('from_date');
if ($from instanceof sfWidgetFormDate) {
$from = new sfWidgetFormJQueryDate(array(
'image' => '/images/calendar.gif',
'culture' => 'en',
'date_widget' => $from
));
$widget->setOption('from_date', $from);
}
$to = $widget->getOption('to_date');
if ($to instanceof sfWidgetFormDate) {
$to = new sfWidgetFormJQueryDate(array(
'image' => '/images/calendar.gif',
'culture' => 'en',
'date_widget' => $to
));
$widget->setOption('to_date', $to);
}
}
}
}
Post a Comment