Permalink
Browse files

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

  • Loading branch information...
2 parents 2b353e9 + c9e047c commit 76d6864d90e51746e03608185d92d2cd0c706574 @markstory markstory committed Jan 28, 2010
Showing with 30 additions and 7 deletions.
  1. +15 −7 cake/libs/view/helpers/form.php
  2. +15 −0 cake/tests/cases/libs/view/helpers/form.test.php
@@ -306,7 +306,7 @@ function create($model = null, $options = array()) {
*
* {{{
* array usage:
- *
+ *
* array('label' => 'save'); value="save"
* array('label' => 'save', 'name' => 'Whatever'); value="save" name="Whatever"
* array('name' => 'Whatever'); value="Submit" name="Whatever"
@@ -389,7 +389,7 @@ function secure($fields = array()) {
}
/**
- * Determine which fields of a form should be used for hash.
+ * Determine which fields of a form should be used for hash.
* Populates $this->fields
*
* @param mixed $field Reference to field to be secured
@@ -644,7 +644,7 @@ function inputs($fields = null, $blacklist = null) {
*
* - `type` - Force the type of widget you want. e.g. `type => 'select'`
* - `label` - Either a string label, or an array of options for the label. See FormHelper::label()
- * - `div` - Either `false` to disable the div, or an array of options for the div.
+ * - `div` - Either `false` to disable the div, or an array of options for the div.
* See HtmlHelper::div() for more options.
* - `options` - for widgets that take options e.g. radio, select
* - `error` - control the error message that is produced
@@ -1412,6 +1412,8 @@ function day($fieldName, $selected = null, $attributes = array()) {
*
* - `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 @@ function year($fieldName, $minYear = null, $maxYear = null, $selected = null, $a
} 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
);
}
@@ -1862,7 +1868,7 @@ function __selectOptions($elements = array(), $selected = null, $parents = array
if ($name !== null) {
if (
- (!$selectedIsArray && !$selectedIsEmpty && (string)$selected == (string)$name) ||
+ (!$selectedIsArray && !$selectedIsEmpty && (string)$selected == (string)$name) ||
($selectedIsArray && in_array($name, $selected))
) {
if ($attributes['style'] === 'checkbox') {
@@ -2005,7 +2011,9 @@ function __generateOptions($name, $options = array()) {
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;
@@ -4465,6 +4465,21 @@ function testYear() {
);
$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(

0 comments on commit 76d6864

Please sign in to comment.