Skip to content

Commit

Permalink
Fixing selected with interval not selecting the correct option. Fixes…
Browse files Browse the repository at this point in the history
… #70.
  • Loading branch information
markstory committed Sep 4, 2009
1 parent fb476f1 commit cf35217
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
7 changes: 4 additions & 3 deletions cake/libs/view/helpers/form.php
Expand Up @@ -1610,15 +1610,16 @@ function dateTime($fieldName, $dateFormat = 'DMY', $timeFormat = '12', $selected
}
$opt = implode($separator, $selects);
}

if (!empty($interval) && $interval > 1 && !empty($min)) {
$min = round($min * (1 / $interval)) * $interval;
}
$selectMinuteAttr['interval'] = $interval;
switch ($timeFormat) {
case '24':
$selectMinuteAttr['interval'] = $interval;
$opt .= $this->hour($fieldName, true, $hour, $selectHourAttr, $showEmpty) . ':' .
$this->minute($fieldName, $min, $selectMinuteAttr, $showEmpty);
break;
case '12':
$selectMinuteAttr['interval'] = $interval;
$opt .= $this->hour($fieldName, false, $hour, $selectHourAttr, $showEmpty) . ':' .
$this->minute($fieldName, $min, $selectMinuteAttr, $showEmpty) . ' ' .
$this->meridian($fieldName, $meridian, $selectMeridianAttr, $showEmpty);
Expand Down
12 changes: 12 additions & 0 deletions cake/tests/cases/libs/view/helpers/form.test.php
Expand Up @@ -3675,6 +3675,18 @@ function testDateTime() {
':',
);
$this->assertTags($result, $expected);

$result = $this->Form->input('published', array(
'timeFormat' => 24,
'interval' => 5,
'selected' => strtotime('2009-09-03 13:37:00'),
'type' => 'datetime'
));
$this->assertPattern('/<option[^<>]+value="2009"[^<>]+selected="selected"[^>]*>2009<\/option>/', $result);
$this->assertPattern('/<option[^<>]+value="09"[^<>]+selected="selected"[^>]*>September<\/option>/', $result);
$this->assertPattern('/<option[^<>]+value="03"[^<>]+selected="selected"[^>]*>3<\/option>/', $result);
$this->assertPattern('/<option[^<>]+value="13"[^<>]+selected="selected"[^>]*>13<\/option>/', $result);
$this->assertPattern('/<option[^<>]+value="35"[^<>]+selected="selected"[^>]*>35<\/option>/', $result);
}
/**
* testFormDateTimeMulti method
Expand Down

0 comments on commit cf35217

Please sign in to comment.