/** * Render field * * @param string $name Element name * @param string $value Field value [optional] * @param array $attributes HTML attributes [optional] * @param array $errors Field errors [optional] * @return string XHTML compliant tag */ public function render($name, $value = null, $attributes = array(), $errors = array()) { if (!is_array($value)) { $value = (string) $value == (string) (int) $value ? (int) $value : strtotime($value); if (false === $value) { $value = ''; } else { $value = array('year' => date('Y', $value), 'month' => date('m', $value), 'day' => date('d', $value)); } } $dateValue = ''; if (is_array($value)) { $value = array_merge(array('year' => null, 'month' => null, 'day' => null), $value); $dateValue = strtr($this->getOption('format'), array('%month%' => $value['month'], '%year%' => $value['year'], '%day%' => $value['day'])); } $widget = new sfWidgetFormInputText(array(), $attributes); return $widget->render($name, $dateValue) . '<script type="text/javascript">if(typeof jQuery!=\'undefined\'){$(function(){$("#' . $widget->generateId($name, $dateValue) . '").datepicker(' . ($this->getOption('config') ? '{' . $this->getOption('config') . '}' : '') . ');});' . ($this->getOption('lang') ? '$("#' . $widget->generateId($name, $dateValue) . '").datepicker($.datepicker.regional[\'' . $this->getOption('lang') . '\']);' : '') . '}</script>'; }