mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
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:
parent
ace586e367
commit
f25e84f4fb
2 changed files with 24 additions and 1 deletions
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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'];
|
||||
|
|
Loading…
Reference in a new issue