public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     $wrapperClass = '';
     $themes = sfConfig::get('dm_dmDatePickerPlugin_themes');
     if (isset($themes[$this->getOption('theme')]) && isset($themes[$this->getOption('theme')]['wrapper_class']) && $themes[$this->getOption('theme')]['wrapper_class']) {
         $wrapperClass = $themes[$this->getOption('theme')]['wrapper_class'];
     }
     $themes = sfConfig::get('dm_dmTimePickerPlugin_themes');
     if (isset($themes[$this->getOption('theme')]) && isset($themes[$this->getOption('theme')]['wrapper_class']) && $themes[$this->getOption('theme')]['wrapper_class']) {
         if ($wrapperClass) {
             // Merge wrapper classes
             $wrapperClass .= ' ' . $themes[$this->getOption('theme')]['wrapper_class'];
         } else {
             $wrapperClass = $themes[$this->getOption('theme')]['wrapper_class'];
         }
     }
     $wrapperClass = implode(' ', array_unique(array_map('trim', explode(' ', $wrapperClass))));
     return sprintf('<div %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s class="sfWidgetFormDmDateTimePicker">%s</div>', sprintf('data-ui-date-format="%s"', $this->getOption('ui_date_format')), sprintf('data-ui-number-of-months="%s"', $this->getOption('ui_number_of_months')), sprintf('data-ui-show-button-panel="%s"', $this->getOption('ui_show_button_panel') ? 'true' : 'false'), sprintf('data-ui-change-month="%s"', $this->getOption('ui_change_month') ? 'true' : 'false'), sprintf('data-ui-change-year="%s"', $this->getOption('ui_change_year') ? 'true' : 'false'), sprintf('data-ui-constrain-input="%s"', $this->getOption('constrain_input') ? 'true' : 'false'), sprintf('data-ui-time-format="%s"', $this->getOption('ui_time_format')), sprintf('data-ui-control-type="%s"', $this->getOption('ui_control_type')), sprintf('data-ui-show-button-panel="%s"', $this->getOption('ui_show_button_panel') ? 'true' : 'false'), sprintf('data-ui-step-hour="%s"', $this->getOption('ui_step_hour')), sprintf('data-ui-step-minute="%s"', $this->getOption('ui_step_minute')), sprintf('data-ui-step-second="%s"', $this->getOption('ui_step_second')), sprintf('data-ui-hour-grid="%s"', $this->getOption('ui_hour_grid')), sprintf('data-ui-minute-grid="%s"', $this->getOption('ui_minute_grid')), sprintf('data-ui-second-grid="%s"', $this->getOption('ui_second_grid')), sprintf('data-ui-wrapper-class="%s"', $wrapperClass), sprintf('data-ui-button-open="%s"', htmlentities($this->getOption('ui_button_open'))), sprintf('data-ui-button-clear="%s"', htmlentities($this->getOption('ui_button_clear'))), parent::render($name, $value, $attributes, $errors));
 }
Ejemplo n.º 2
0
$w->setOption('time', array('format' => '%hour%!%minute%!%second%', 'with_seconds' => true));
$dom->loadHTML($w->render('foo', '2005-10-15 12:30:35'));
$css = new sfDomCssSelector($dom);
$t->is($css->matchSingle('#foo_day')->getNode()->nextSibling->nodeValue, '-', '__construct() can change the default format');
$t->like($css->matchSingle('#foo_month')->getNode()->nextSibling->nodeValue, '/^-/', '__construct() can change the default format');
$t->is($css->matchSingle('#foo_hour')->getNode()->nextSibling->nodeValue, '!', '__construct() can change the default format');
$t->is($css->matchSingle('#foo_minute')->getNode()->nextSibling->nodeValue, '!', '__construct() can change the default format');
// with_time option
$t->diag('with_time option');
$w = new sfWidgetFormDateTime(array('with_time' => false));
$dom->loadHTML($w->render('foo', '2005-10-15 12:30:35'));
$css = new sfDomCssSelector($dom);
$t->is(count($css->matchAll('#foo_hour')->getNodes()), 0, '->render() does not render the time if the with_time option is disabled');
// date and time options as array
$t->diag('date and time options as array');
$w = new sfWidgetFormDateTime(array('date' => 'a string'));
try {
    $w->render('foo');
    $t->fail('__construct() throws a InvalidArgumentException if the date/time options is not an array');
} catch (InvalidArgumentException $e) {
    $t->pass('__construct() throws a InvalidArgumentException if the date/time options is not an array');
}
// attributes
$t->diag('attributes');
$w = new sfWidgetFormDateTime();
$dom->loadHTML($w->render('foo', '2005-10-15 12:30:35', array('date' => array('disabled' => 'disabled'), 'time' => array('disabled' => 'disabled'))));
$t->is(count($css->matchAll('select[disabled="disabled"]')->getNodes()), 5, '->render() takes the attributes into account for all the five embedded widgets');
$w->setAttribute('date', array('disabled' => 'disabled'));
$w->setAttribute('time', array('disabled' => 'disabled'));
$dom->loadHTML($w->render('foo', '2005-10-15 12:30:35'));
$t->is(count($css->matchAll('select[disabled="disabled"]')->getNodes()), 5, '->render() takes the attributes into account for all the five embedded widgets');
Ejemplo n.º 3
0
    $t->fail('__construct() throws a InvalidArgumentException if the date/time options is not an array');
} catch (InvalidArgumentException $e) {
    $t->pass('__construct() throws a InvalidArgumentException if the date/time options is not an array');
}
// attributes
$t->diag('attributes');
$w = new sfWidgetFormDateTime();
$dom->loadHTML($w->render('foo', $year . '-10-15 12:30:35', array('date' => array('disabled' => 'disabled'), 'time' => array('disabled' => 'disabled'))));
$t->is(count($css->matchAll('select[disabled="disabled"]')->getNodes()), 5, '->render() takes the attributes into account for all the five embedded widgets');
$w->setAttribute('date', array('disabled' => 'disabled'));
$w->setAttribute('time', array('disabled' => 'disabled'));
$dom->loadHTML($w->render('foo', $year . '-10-15 12:30:35'));
$t->is(count($css->matchAll('select[disabled="disabled"]')->getNodes()), 5, '->render() takes the attributes into account for all the five embedded widgets');
// id_format
$t->diag('id_format');
$w = new sfWidgetFormDateTime();
$w->setIdFormat('id_%s');
$dom->loadHTML($w->render('foo'));
$t->is(count($css->matchAll('#id_foo_month')), 1, '->render() month considers id_format');
$t->is(count($css->matchAll('#id_foo_day')), 1, '->render() day considers id_format');
$t->is(count($css->matchAll('#id_foo_year')), 1, '->render() year considers id_format');
$t->is(count($css->matchAll('#id_foo_hour')), 1, '->render() hour considers id_format');
$t->is(count($css->matchAll('#id_foo_minute')), 1, '->render() minute considers id_format');
$w->setOption('date', array('id_format' => 'override_%s'));
$w->setOption('time', array('id_format' => 'override_%s'));
$dom->loadHTML($w->render('foo'));
$t->is(count($css->matchAll('#override_foo_month')), 1, '->render() month does not override subwidget id_format');
$t->is(count($css->matchAll('#override_foo_day')), 1, '->render() day does not override subwidget id_format');
$t->is(count($css->matchAll('#override_foo_year')), 1, '->render() year does not override subwidget id_format');
$t->is(count($css->matchAll('#override_foo_hour')), 1, '->render() hour does not override subwidget id_format');
$t->is(count($css->matchAll('#override_foo_minute')), 1, '->render() minute does not override subwidget id_format');