Skip to content

Commit

Permalink
Fixing FormHelper::input() label's for attribute when a datetime type…
Browse files Browse the repository at this point in the history
… is created and dateFormat or timeFormat is set to NONE. Fixes #168
  • Loading branch information
markstory committed Oct 15, 2009
1 parent 604b7e0 commit 082156f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
16 changes: 10 additions & 6 deletions cake/libs/view/helpers/form.php
Expand Up @@ -708,9 +708,13 @@ function input($fieldName, $options = array()) {

if ($label !== false) {
$labelAttributes = $this->domId(array(), 'for');
if (in_array($options['type'], array('date', 'datetime'))) {
$labelAttributes['for'] .= 'Month';
} else if ($options['type'] === 'time') {
if ($options['type'] === 'date' || $options['type'] === 'datetime') {
if (isset($options['dateFormat']) && $options['dateFormat'] === 'NONE') {
$labelAttributes['for'] .= 'Hour';
} else {
$labelAttributes['for'] .= 'Month';
}
} elseif ($options['type'] === 'time') {
$labelAttributes['for'] .= 'Hour';
}

Expand Down Expand Up @@ -764,10 +768,10 @@ function input($fieldName, $options = array()) {
unset($options['dateFormat']);
}

$type = $options['type'];
$before = $options['before'];
$type = $options['type'];
$before = $options['before'];
$between = $options['between'];
$after = $options['after'];
$after = $options['after'];
unset($options['type'], $options['before'], $options['between'], $options['after']);

switch ($type) {
Expand Down
8 changes: 8 additions & 0 deletions cake/tests/cases/libs/view/helpers/form.test.php
Expand Up @@ -1769,6 +1769,14 @@ function testInputDatetime() {
'/div'
);
$this->assertTags($result, $expected);

$this->Form->data = array('Contact' => array('created' => null));
$result = $this->Form->input('Contact.created', array('type' => 'datetime', 'dateFormat' => 'NONE'));
$this->assertPattern('/for\="ContactCreatedHour"/', $result);

$this->Form->data = array('Contact' => array('created' => null));
$result = $this->Form->input('Contact.created', array('type' => 'datetime', 'timeFormat' => 'NONE'));
$this->assertPattern('/for\="ContactCreatedMonth"/', $result);
}
/**
* Test generating checkboxes in a loop.
Expand Down

0 comments on commit 082156f

Please sign in to comment.