Don't select year 0 when there are all 0's.

Year 0 is almost never a 'good' selection value and causes odd behavior
when paired with MySQL.

Fixes #2658
This commit is contained in:
mark_story 2014-01-15 10:23:45 -05:00
parent ace586e367
commit f25e84f4fb
2 changed files with 24 additions and 1 deletions

View file

@ -6273,6 +6273,25 @@ class FormHelperTest extends CakeTestCase {
$this->assertNotRegExp('/selected="selected">\d/', $result);
}
/**
* testDateTime all zeros
*
* @return void
*/
public function testDateTimeAllZeros() {
$result = $this->Form->dateTime('Contact.date',
'DMY',
false,
array(
'empty' => array('day' => '-', 'month' => '-', 'year' => '-'),
'value' => '0000-00-00'
)
);
$this->assertRegExp('/<option value="">-<\/option>/', $result);
$this->assertNotRegExp('/<option value="0" selected="selected">0<\/option>/', $result);
}
/**
* testDateTimeEmptyAsArray
*

View file

@ -2825,7 +2825,11 @@ class FormHelper extends AppHelper {
if ($min > $max) {
list($min, $max) = array($max, $min);
}
if (!empty($options['value']) && (int)$options['value'] < $min) {
if (
!empty($options['value']) &&
(int)$options['value'] < $min &&
(int)$options['value'] > 0
) {
$min = (int)$options['value'];
} elseif (!empty($options['value']) && (int)$options['value'] > $max) {
$max = (int)$options['value'];