Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing selected with interval not selecting the correct option. Fixes #…

  • Loading branch information...
commit cf3521737f86d207458b58edb31ae62f022c5c29 1 parent fb476f1
Mark Story markstory authored
7 cake/libs/view/helpers/form.php
View
@@ -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);
12 cake/tests/cases/libs/view/helpers/form.test.php
View
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.