Skip to content

Commit cf35217

Browse files
committed
Fixing selected with interval not selecting the correct option. Fixes #70.
1 parent fb476f1 commit cf35217

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

cake/libs/view/helpers/form.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,15 +1610,16 @@ function dateTime($fieldName, $dateFormat = 'DMY', $timeFormat = '12', $selected
16101610
}
16111611
$opt = implode($separator, $selects);
16121612
}
1613-
1613+
if (!empty($interval) && $interval > 1 && !empty($min)) {
1614+
$min = round($min * (1 / $interval)) * $interval;
1615+
}
1616+
$selectMinuteAttr['interval'] = $interval;
16141617
switch ($timeFormat) {
16151618
case '24':
1616-
$selectMinuteAttr['interval'] = $interval;
16171619
$opt .= $this->hour($fieldName, true, $hour, $selectHourAttr, $showEmpty) . ':' .
16181620
$this->minute($fieldName, $min, $selectMinuteAttr, $showEmpty);
16191621
break;
16201622
case '12':
1621-
$selectMinuteAttr['interval'] = $interval;
16221623
$opt .= $this->hour($fieldName, false, $hour, $selectHourAttr, $showEmpty) . ':' .
16231624
$this->minute($fieldName, $min, $selectMinuteAttr, $showEmpty) . ' ' .
16241625
$this->meridian($fieldName, $meridian, $selectMeridianAttr, $showEmpty);

cake/tests/cases/libs/view/helpers/form.test.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3675,6 +3675,18 @@ function testDateTime() {
36753675
':',
36763676
);
36773677
$this->assertTags($result, $expected);
3678+
3679+
$result = $this->Form->input('published', array(
3680+
'timeFormat' => 24,
3681+
'interval' => 5,
3682+
'selected' => strtotime('2009-09-03 13:37:00'),
3683+
'type' => 'datetime'
3684+
));
3685+
$this->assertPattern('/<option[^<>]+value="2009"[^<>]+selected="selected"[^>]*>2009<\/option>/', $result);
3686+
$this->assertPattern('/<option[^<>]+value="09"[^<>]+selected="selected"[^>]*>September<\/option>/', $result);
3687+
$this->assertPattern('/<option[^<>]+value="03"[^<>]+selected="selected"[^>]*>3<\/option>/', $result);
3688+
$this->assertPattern('/<option[^<>]+value="13"[^<>]+selected="selected"[^>]*>13<\/option>/', $result);
3689+
$this->assertPattern('/<option[^<>]+value="35"[^<>]+selected="selected"[^>]*>35<\/option>/', $result);
36783690
}
36793691
/**
36803692
* testFormDateTimeMulti method

0 commit comments

Comments
 (0)