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

This commit is contained in:
mark_story 2009-09-03 22:47:17 -04:00
parent fb476f17cc
commit cf3521737f
2 changed files with 16 additions and 3 deletions

View file

@ -1610,15 +1610,16 @@ class FormHelper extends AppHelper {
} }
$opt = implode($separator, $selects); $opt = implode($separator, $selects);
} }
if (!empty($interval) && $interval > 1 && !empty($min)) {
$min = round($min * (1 / $interval)) * $interval;
}
$selectMinuteAttr['interval'] = $interval;
switch ($timeFormat) { switch ($timeFormat) {
case '24': case '24':
$selectMinuteAttr['interval'] = $interval;
$opt .= $this->hour($fieldName, true, $hour, $selectHourAttr, $showEmpty) . ':' . $opt .= $this->hour($fieldName, true, $hour, $selectHourAttr, $showEmpty) . ':' .
$this->minute($fieldName, $min, $selectMinuteAttr, $showEmpty); $this->minute($fieldName, $min, $selectMinuteAttr, $showEmpty);
break; break;
case '12': case '12':
$selectMinuteAttr['interval'] = $interval;
$opt .= $this->hour($fieldName, false, $hour, $selectHourAttr, $showEmpty) . ':' . $opt .= $this->hour($fieldName, false, $hour, $selectHourAttr, $showEmpty) . ':' .
$this->minute($fieldName, $min, $selectMinuteAttr, $showEmpty) . ' ' . $this->minute($fieldName, $min, $selectMinuteAttr, $showEmpty) . ' ' .
$this->meridian($fieldName, $meridian, $selectMeridianAttr, $showEmpty); $this->meridian($fieldName, $meridian, $selectMeridianAttr, $showEmpty);

View file

@ -3675,6 +3675,18 @@ class FormHelperTest extends CakeTestCase {
':', ':',
); );
$this->assertTags($result, $expected); $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 * testFormDateTimeMulti method