From c25ed9016a0c22ed96e2484aabe7e7b41cd35331 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 3 Jul 2008 00:46:42 +0000 Subject: [PATCH] Fixed attributes being set for select elements in formHelper::dateTime() when $options[id] is specified. Closes #5013. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7306 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/view/helpers/form.php | 2 ++ cake/tests/cases/libs/view/helpers/form.test.php | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 346cfa46a..b01b02e71 100644 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -444,6 +444,7 @@ class FormHelper extends AppHelper { * * @param string $fieldName This should be "Modelname.fieldname", "Modelname/fieldname" is deprecated * @param string $text Text that will appear in the label field. + * @param array $attributes Array of HTML attributes. * @return string The formatted LABEL element */ function label($fieldName = null, $text = null, $attributes = array()) { @@ -1437,6 +1438,7 @@ class FormHelper extends AppHelper { // build out an array version foreach ($elements as $element) { $selectAttrName = 'select' . $element . 'Attr'; + ${$selectAttrName} = $attributes; ${$selectAttrName}['id'] = $attributes['id'] . $element; } } elseif (is_array($attributes['id'])) { diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 0679a43d1..a3fab462a 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -1214,7 +1214,19 @@ class FormHelperTest extends CakeTestCase { $result = explode(':', $result); $this->assertPattern('/option value="12"/', $result[0]); $this->assertNoPattern('/option value="13"/', $result[0]); + + //related to ticket #5013 + $result = $this->Form->input('Contact.date', array('type' => 'date', 'class' => 'customClass', 'onChange' => 'function(){}')); + $this->assertPattern('/class="customClass"/', $result); + $this->assertPattern('/onChange="function\(\)\{\}"/', $result); + Configure::write('test', true); + $result = $this->Form->input('Contact.date', array('type' => 'date', 'id' => 'customId', 'onChange' => 'function(){}')); + $this->assertPattern('/id="customIdDay"/', $result); + $this->assertPattern('/id="customIdMonth"/', $result); + $this->assertPattern('/onChange="function\(\)\{\}"/', $result); + Configure::write('test', false); + $result = $this->Form->input('Model.field', array('type' => 'datetime', 'timeFormat' => 24, 'id' => 'customID')); $this->assertPattern('/id="customIDDay"/', $result); $this->assertPattern('/id="customIDHour"/', $result);