Changeset 8907
- Timestamp:
- 05/10/08 23:39:17 (4 months ago)
- Files:
-
- branches/1.1/lib/widget/sfWidgetFormDate.class.php (modified) (1 diff)
- branches/1.1/lib/widget/sfWidgetFormDateTime.class.php (modified) (5 diffs)
- branches/1.1/lib/widget/sfWidgetFormTime.class.php (modified) (2 diffs)
- branches/1.1/test/unit/widget/sfWidgetFormDateTest.php (modified) (2 diffs)
- branches/1.1/test/unit/widget/sfWidgetFormDateTimeTest.php (modified) (2 diffs)
- branches/1.1/test/unit/widget/sfWidgetFormTimeTest.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.1/lib/widget/sfWidgetFormDate.class.php
r6948 r8907 73 73 74 74 // 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)); 76 76 $date['%day%'] = $widget->render($name.'[day]', $value['day']); 77 77 78 78 // 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)); 80 80 $date['%month%'] = $widget->render($name.'[month]', $value['month']); 81 81 82 82 // 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)); 84 84 $date['%year%'] = $widget->render($name.'[year]', $value['year']); 85 85 branches/1.1/lib/widget/sfWidgetFormDateTime.class.php
r6340 r8907 19 19 class sfWidgetFormDateTime extends sfWidgetForm 20 20 { 21 protected22 $defaultAttributes = array('date' => array(), 'time' => array());23 24 21 /** 25 22 * Configures the current widget. … … 45 42 $this->addOption('with_time', true); 46 43 $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 }59 44 } 60 45 … … 65 50 { 66 51 // date 67 $date = $this->getDateWidget( )->render($name, $value);52 $date = $this->getDateWidget($attributes)->render($name, $value); 68 53 69 54 if (!$this->getOption('with_time')) … … 74 59 return strtr($this->getOption('format'), array( 75 60 '%date%' => $date, 76 '%time%' => $this->getTimeWidget( )->render($name, $value),61 '%time%' => $this->getTimeWidget($attributes)->render($name, $value), 77 62 )); 78 63 } 79 64 80 65 /** 81 * Returns the date widget 66 * Returns the date widget. 67 * 68 * @param array An array of attributes 82 69 * 83 70 * @return sfWidgetForm A Widget representing the date 84 71 */ 85 protected function getDateWidget( )72 protected function getDateWidget($attributes) 86 73 { 87 return new sfWidgetFormDate($this->getOptionsFor('date'), $this->getAttributesFor('date' ));74 return new sfWidgetFormDate($this->getOptionsFor('date'), $this->getAttributesFor('date', $attributes)); 88 75 } 89 76 90 77 /** 91 * Returns the time widget 78 * Returns the time widget. 79 * 80 * @param array An array of attributes 92 81 * 93 82 * @return sfWidgetForm A Widget representing the time 94 83 */ 95 protected function getTimeWidget( )84 protected function getTimeWidget($attributes) 96 85 { 97 return new sfWidgetFormTime($this->getOptionsFor('time'), $this->getAttributesFor('time' ));86 return new sfWidgetFormTime($this->getOptionsFor('time'), $this->getAttributesFor('time', $attributes)); 98 87 } 99 88 100 89 /** 101 * Returns an array of options for the given type 90 * Returns an array of options for the given type. 102 91 * 103 92 * @param string The type (date or time) … … 117 106 118 107 /** 119 * Returns an array of HTML attributes for the given type 108 * Returns an array of HTML attributes for the given type. 120 109 * 121 110 * @param string The type (date or time) 111 * @param array An array of attributes 122 112 * 123 113 * @return array An array of HTML attributes 124 114 */ 125 protected function getAttributesFor($type )115 protected function getAttributesFor($type, $attributes) 126 116 { 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; 128 120 } 129 121 } branches/1.1/lib/widget/sfWidgetFormTime.class.php
r6948 r8907 76 76 77 77 // 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)); 79 79 $time['%hour%'] = $widget->render($name.'[hour]', $value['hour']); 80 80 81 81 // 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)); 83 83 $time['%minute%'] = $widget->render($name.'[minute]', $value['minute']); 84 84 … … 86 86 { 87 87 // 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)); 89 89 $time['%second%'] = $widget->render($name.'[second]', $value['second']); 90 90 } branches/1.1/test/unit/widget/sfWidgetFormDateTest.php
r6948 r8907 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 12 13 $t = new lime_test(3 5, new lime_output_color());13 $t = new lime_test(37, new lime_output_color()); 14 14 15 15 $w = new sfWidgetFormDate(); … … 113 113 $t->is(count($css->matchAll('#foo_month option')->getNodes()), 4, '__construct() can change the default array used for months'); 114 114 $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 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 12 13 $t = new lime_test(5 2, new lime_output_color());13 $t = new lime_test(54, new lime_output_color()); 14 14 15 15 $dom = new DomDocument('1.0', 'utf-8'); … … 120 120 $t->pass('__construct() throws a InvalidArgumentException if the date/time options is not an array'); 121 121 } 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 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 12 13 $t = new lime_test(3 5, new lime_output_color());13 $t = new lime_test(37, new lime_output_color()); 14 14 15 15 $w = new sfWidgetFormTime(array('with_seconds' => true)); … … 124 124 $t->like($css->matchSingle('#foo_hour')->getNode()->nextSibling->nodeValue, '/^#/', '__construct() can change the default format'); 125 125 $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');