Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing FormHelper::input() label's for attribute when a datetime type…

… is created and dateFormat or timeFormat is set to NONE. Fixes #168
  • Loading branch information...
commit 082156f9a1842b3d3c5e0afca48c4dba69ccab12 1 parent 604b7e0
Mark Story markstory authored
16 cake/libs/view/helpers/form.php
View
@@ -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';
}
@@ -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) {
8 cake/tests/cases/libs/view/helpers/form.test.php
View
@@ -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.
Please sign in to comment.
Something went wrong with that request. Please try again.