Development

Changeset 8907

You must first sign up to be able to contribute.

Changeset 8907

Show
Ignore:
Timestamp:
05/10/08 23:39:17 (4 months ago)
Author:
fabien
Message:

fixed HTML attributes for Date, Time, and DateTime? widgets (closes #3480)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/widget/sfWidgetFormDate.class.php

    r6948 r8907  
    7373 
    7474    // days 
    75     $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['day']) + $this->getOption('days') : $this->getOption('days'))); 
     75    $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['day']) + $this->getOption('days') : $this->getOption('days')), array_merge($this->attributes, $attributes)); 
    7676    $date['%day%'] = $widget->render($name.'[day]', $value['day']); 
    7777 
    7878    // months 
    79     $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['month']) + $this->getOption('months') : $this->getOption('months'))); 
     79    $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['month']) + $this->getOption('months') : $this->getOption('months')), array_merge($this->attributes, $attributes)); 
    8080    $date['%month%'] = $widget->render($name.'[month]', $value['month']); 
    8181 
    8282    // years 
    83     $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['year']) + $this->getOption('years') : $this->getOption('years'))); 
     83    $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['year']) + $this->getOption('years') : $this->getOption('years')), array_merge($this->attributes, $attributes)); 
    8484    $date['%year%'] = $widget->render($name.'[year]', $value['year']); 
    8585 
  • branches/1.1/lib/widget/sfWidgetFormDateTime.class.php

    r6340 r8907  
    1919class sfWidgetFormDateTime extends sfWidgetForm 
    2020{ 
    21   protected 
    22     $defaultAttributes = array('date' => array(), 'time' => array()); 
    23  
    2421  /** 
    2522   * Configures the current widget. 
     
    4542    $this->addOption('with_time', true); 
    4643    $this->addOption('format', '%date% %time%'); 
    47  
    48     if (isset($attributes['date'])) 
    49     { 
    50       $defaultAttributes['time'] = $attributes['date']; 
    51       unset($attributes['date']); 
    52     } 
    53  
    54     if (isset($attributes['time'])) 
    55     { 
    56       $defaultAttributes['time'] = $attributes['time']; 
    57       unset($attributes['time']); 
    58     } 
    5944  } 
    6045 
     
    6550  { 
    6651    // date 
    67     $date = $this->getDateWidget()->render($name, $value); 
     52    $date = $this->getDateWidget($attributes)->render($name, $value); 
    6853 
    6954    if (!$this->getOption('with_time')) 
     
    7459    return strtr($this->getOption('format'), array( 
    7560      '%date%' => $date, 
    76       '%time%' => $this->getTimeWidget()->render($name, $value), 
     61      '%time%' => $this->getTimeWidget($attributes)->render($name, $value), 
    7762    )); 
    7863  } 
    7964 
    8065  /** 
    81    * Returns the date widget 
     66   * Returns the date widget. 
     67   * 
     68   * @param  array  An array of attributes 
    8269   * 
    8370   * @return sfWidgetForm A Widget representing the date 
    8471   */ 
    85   protected function getDateWidget(
     72  protected function getDateWidget($attributes
    8673  { 
    87     return new sfWidgetFormDate($this->getOptionsFor('date'), $this->getAttributesFor('date')); 
     74    return new sfWidgetFormDate($this->getOptionsFor('date'), $this->getAttributesFor('date', $attributes)); 
    8875  } 
    8976 
    9077  /** 
    91    * Returns the time widget 
     78   * Returns the time widget. 
     79   * 
     80   * @param  array  An array of attributes 
    9281   * 
    9382   * @return sfWidgetForm A Widget representing the time 
    9483   */ 
    95   protected function getTimeWidget(
     84  protected function getTimeWidget($attributes
    9685  { 
    97     return new sfWidgetFormTime($this->getOptionsFor('time'), $this->getAttributesFor('time')); 
     86    return new sfWidgetFormTime($this->getOptionsFor('time'), $this->getAttributesFor('time', $attributes)); 
    9887  } 
    9988 
    10089  /** 
    101    * Returns an array of options for the given type 
     90   * Returns an array of options for the given type. 
    10291   * 
    10392   * @param  string The type (date or time) 
     
    117106 
    118107  /** 
    119    * Returns an array of HTML attributes for the given type 
     108   * Returns an array of HTML attributes for the given type. 
    120109   * 
    121110   * @param  string The type (date or time) 
     111   * @param  array  An array of attributes 
    122112   * 
    123113   * @return array  An array of HTML attributes 
    124114   */ 
    125   protected function getAttributesFor($type
     115  protected function getAttributesFor($type, $attributes
    126116  { 
    127     return isset($attributes[$type]) ? array_merge($this->defaultAttributes[$type], $attributes[$type]) : $this->defaultAttributes[$type]; 
     117    $defaults = isset($this->attributes[$type]) ? $this->attributes[$type] : array(); 
     118 
     119    return isset($attributes[$type]) ? array_merge($defaults, $attributes[$type]) : $defaults; 
    128120  } 
    129121} 
  • branches/1.1/lib/widget/sfWidgetFormTime.class.php

    r6948 r8907  
    7676 
    7777    // hours 
    78     $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['hour']) + $this->getOption('hours') : $this->getOption('hours'))); 
     78    $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['hour']) + $this->getOption('hours') : $this->getOption('hours')), array_merge($this->attributes, $attributes)); 
    7979    $time['%hour%'] = $widget->render($name.'[hour]', $value['hour']); 
    8080 
    8181    // minutes 
    82     $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['minute']) + $this->getOption('minutes') : $this->getOption('minutes'))); 
     82    $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['minute']) + $this->getOption('minutes') : $this->getOption('minutes')), array_merge($this->attributes, $attributes)); 
    8383    $time['%minute%'] = $widget->render($name.'[minute]', $value['minute']); 
    8484 
     
    8686    { 
    8787      // seconds 
    88       $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['second']) + $this->getOption('seconds') : $this->getOption('seconds'))); 
     88      $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['second']) + $this->getOption('seconds') : $this->getOption('seconds')), array_merge($this->attributes, $attributes)); 
    8989      $time['%second%'] = $widget->render($name.'[second]', $value['second']); 
    9090    } 
  • branches/1.1/test/unit/widget/sfWidgetFormDateTest.php

    r6948 r8907  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(35, new lime_output_color()); 
     13$t = new lime_test(37, new lime_output_color()); 
    1414 
    1515$w = new sfWidgetFormDate(); 
     
    113113$t->is(count($css->matchAll('#foo_month option')->getNodes()), 4, '__construct() can change the default array used for months'); 
    114114$t->is(count($css->matchAll('#foo_day option')->getNodes()), 3, '__construct() can change the default array used for days'); 
     115 
     116// attributes 
     117$t->diag('attributes'); 
     118$dom->loadHTML($w->render('foo', '2005-10-15', array('disabled' => 'disabled'))); 
     119$t->is(count($css->matchAll('select[disabled="disabled"]')->getNodes()), 3, '->render() takes the attributes into account for all the three embedded widgets'); 
     120 
     121$w->setAttribute('disabled', 'disabled'); 
     122$dom->loadHTML($w->render('foo', '2005-10-15')); 
     123$t->is(count($css->matchAll('select[disabled="disabled"]')->getNodes()), 3, '->render() takes the attributes into account for all the three embedded widgets'); 
  • branches/1.1/test/unit/widget/sfWidgetFormDateTimeTest.php

    r6949 r8907  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(52, new lime_output_color()); 
     13$t = new lime_test(54, new lime_output_color()); 
    1414 
    1515$dom = new DomDocument('1.0', 'utf-8'); 
     
    120120  $t->pass('__construct() throws a InvalidArgumentException if the date/time options is not an array'); 
    121121} 
     122 
     123// attributes 
     124$t->diag('attributes'); 
     125$w = new sfWidgetFormDateTime(); 
     126$dom->loadHTML($w->render('foo', '2005-10-15 12:30:35', array('date' => array('disabled' => 'disabled'), 'time' => array('disabled' => 'disabled')))); 
     127$t->is(count($css->matchAll('select[disabled="disabled"]')->getNodes()), 5, '->render() takes the attributes into account for all the five embedded widgets'); 
     128 
     129$w->setAttribute('date', array('disabled' => 'disabled')); 
     130$w->setAttribute('time', array('disabled' => 'disabled')); 
     131$dom->loadHTML($w->render('foo', '2005-10-15 12:30:35')); 
     132$t->is(count($css->matchAll('select[disabled="disabled"]')->getNodes()), 5, '->render() takes the attributes into account for all the five embedded widgets'); 
  • branches/1.1/test/unit/widget/sfWidgetFormTimeTest.php

    r6948 r8907  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(35, new lime_output_color()); 
     13$t = new lime_test(37, new lime_output_color()); 
    1414 
    1515$w = new sfWidgetFormTime(array('with_seconds' => true)); 
     
    124124$t->like($css->matchSingle('#foo_hour')->getNode()->nextSibling->nodeValue, '/^#/', '__construct() can change the default format'); 
    125125$t->ok(!count($css->matchSingle('#foo_second')->getNodes()), '__construct() can change the default format'); 
     126 
     127// attributes 
     128$t->diag('attributes'); 
     129$w->setOption('with_seconds', true); 
     130$dom->loadHTML($w->render('foo', '12:30:35', array('disabled' => 'disabled'))); 
     131$t->is(count($css->matchAll('select[disabled="disabled"]')->getNodes()), 3, '->render() takes the attributes into account for all the three embedded widgets'); 
     132 
     133$w->setAttribute('disabled', 'disabled'); 
     134$dom->loadHTML($w->render('foo', '12:30:35')); 
     135$t->is(count($css->matchAll('select[disabled="disabled"]')->getNodes()), 3, '->render() takes the attributes into account for all the three embedded widgets');