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
This commit is contained in:
mark_story 2008-07-03 00:46:42 +00:00
parent 80b6e027c1
commit c25ed9016a
2 changed files with 14 additions and 0 deletions

View file

@ -444,6 +444,7 @@ class FormHelper extends AppHelper {
* *
* @param string $fieldName This should be "Modelname.fieldname", "Modelname/fieldname" is deprecated * @param string $fieldName This should be "Modelname.fieldname", "Modelname/fieldname" is deprecated
* @param string $text Text that will appear in the label field. * @param string $text Text that will appear in the label field.
* @param array $attributes Array of HTML attributes.
* @return string The formatted LABEL element * @return string The formatted LABEL element
*/ */
function label($fieldName = null, $text = null, $attributes = array()) { function label($fieldName = null, $text = null, $attributes = array()) {
@ -1437,6 +1438,7 @@ class FormHelper extends AppHelper {
// build out an array version // build out an array version
foreach ($elements as $element) { foreach ($elements as $element) {
$selectAttrName = 'select' . $element . 'Attr'; $selectAttrName = 'select' . $element . 'Attr';
${$selectAttrName} = $attributes;
${$selectAttrName}['id'] = $attributes['id'] . $element; ${$selectAttrName}['id'] = $attributes['id'] . $element;
} }
} elseif (is_array($attributes['id'])) { } elseif (is_array($attributes['id'])) {

View file

@ -1215,6 +1215,18 @@ class FormHelperTest extends CakeTestCase {
$this->assertPattern('/option value="12"/', $result[0]); $this->assertPattern('/option value="12"/', $result[0]);
$this->assertNoPattern('/option value="13"/', $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')); $result = $this->Form->input('Model.field', array('type' => 'datetime', 'timeFormat' => 24, 'id' => 'customID'));
$this->assertPattern('/id="customIDDay"/', $result); $this->assertPattern('/id="customIDDay"/', $result);
$this->assertPattern('/id="customIDHour"/', $result); $this->assertPattern('/id="customIDHour"/', $result);