public function configure($options = array(), $attributes = array())
 {
     $this->addOption('date_widget');
     $this->addOption('time_widget');
     $this->addOption('separate_names');
     parent::configure($options, $attributes);
 }
 /**
  * Constructor.
  *
  * Available options:
  *
  *  * culture: The culture to use for internationalized strings (required)
  *
  * @param array $options     An array of options
  * @param array $attributes  An array of default HTML attributes
  *
  * @see sfWidgetFormDateTime
  */
 protected function configure($options = array(), $attributes = array())
 {
     parent::configure($options, $attributes);
     $this->addRequiredOption('culture');
     $culture = isset($options['culture']) ? $options['culture'] : 'en';
     // format
     $this->setOption('format', str_replace(array('{0}', '{1}'), array('%time%', '%date%'), sfDateTimeFormatInfo::getInstance($culture)->getDateTimeOrderPattern()));
 }
 /**
  * Configures the current widget.
  *
  * Available options:
  *
  *  * image:       The image path to represent the widget (false by default)
  *  * config:      A JavaScript array that configures the JQuery date widget
  *  * culture:     The user culture
  *  * date_widget: The date widget instance to use as a "base" class
  *
  * @param array $options     An array of options
  * @param array $attributes  An array of default HTML attributes
  *
  * @see sfWidgetForm
  */
 protected function configure($options = array(), $attributes = array())
 {
     $this->addOption('image', false);
     $this->addOption('config', '{}');
     $this->addOption('culture', '');
     $this->addOption('date_widget', new sfWidgetFormDate());
     parent::configure($options, $attributes);
     if ('en' == $this->getOption('culture')) {
         $this->setOption('culture', 'en');
     }
 }
$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');
    $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');
Exemple #6
0
 protected function getDatetimeSettingWidget(DmSetting $setting)
 {
     $widget = new sfWidgetFormDateTime(array(), $setting->getParamsArray());
     return $widget->setDefault($setting->get('value'));
 }
 public function getStylesheets()
 {
     return array_merge(parent::getStylesheets(), array("/dcReloadedFormExtraPlugin/css/alTimepicker/jquery.ui.timepicker.css?v=0.2.5" => "screen", "/dcReloadedFormExtraPlugin/css/alTimepicker/reset-tables.css" => "screen"));
 }
 public function getJavaScripts()
 {
     return array_merge(parent::getJavaScripts(), array('lib.ui-core', 'lib.ui-widget', 'lib.ui-mouse', 'lib.ui-slider', 'lib.ui-datepicker', 'lib.ui-i18n', 'dmDateTimePickerPlugin.tp-add-on', 'dmDateTimePickerPlugin.tp-add-on-i18n', 'dmDateTimePickerPlugin.date-time-picker'));
 }