Merge branch '1.3' of github.com:cakephp/cakephp1x into 1.3

This commit is contained in:
Mark Story 2010-01-28 10:55:41 -05:00
commit 76d6864d90
2 changed files with 30 additions and 7 deletions

View file

@ -1412,6 +1412,8 @@ class FormHelper extends AppHelper {
*
* - `empty` - If true, the empty select option is shown. If a string,
* that string is displayed as the empty element.
* - `orderYear` - Ordering of year values in select options.
* Possible values 'asc', 'desc'. Default 'desc'
*
* @param string $fieldName Prefix name for the SELECT element
* @param integer $minYear First year in sequence
@ -1446,9 +1448,13 @@ class FormHelper extends AppHelper {
} elseif ($selected === false) {
$selected = null;
}
$yearOptions = array('min' => $minYear, 'max' => $maxYear);
$yearOptions = array('min' => $minYear, 'max' => $maxYear, 'order' => 'desc');
if (isset($attributes['orderYear'])) {
$yearOptions['order'] = $attributes['orderYear'];
unset($attributes['orderYear']);
}
return $this->select(
$fieldName . ".year", $this->__generateOptions('year', $yearOptions),
$fieldName . '.year', $this->__generateOptions('year', $yearOptions),
$selected, $attributes
);
}
@ -2005,7 +2011,9 @@ class FormHelper extends AppHelper {
for ($i = $min; $i <= $max; $i++) {
$data[$i] = $i;
}
$data = array_reverse($data, true);
if ($options['order'] != 'asc') {
$data = array_reverse($data, true);
}
break;
}
$this->__options[$name] = $data;

View file

@ -4465,6 +4465,21 @@ class FormHelperTest extends CakeTestCase {
);
$this->assertTags($result, $expected);
$result = $this->Form->year('Model.field', 2006, 2007, null, array('orderYear' => 'asc'));
$expected = array(
array('select' => array('name' => 'data[Model][field][year]', 'id' => 'ModelFieldYear')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '2006')),
'2006',
'/option',
array('option' => array('value' => '2007')),
'2007',
'/option',
'/select',
);
$this->assertTags($result, $expected);
$this->data['Contact']['published'] = '';
$result = $this->Form->year('Contact.published', 2006, 2007, null, array('class' => 'year'));
$expected = array(