mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Fix to the date input year field
Create the field if no value is informed only to the maxYear and not to the current date.
This commit is contained in:
parent
691288accc
commit
dc3f9113b0
2 changed files with 30 additions and 1 deletions
|
@ -6628,6 +6628,31 @@ class FormHelperTest extends CakeTestCase {
|
||||||
$this->assertEquals($result, $expected);
|
$this->assertEquals($result, $expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testInputDateMaxYear method
|
||||||
|
*
|
||||||
|
* Let's say we want to only allow users born from
|
||||||
|
* 2006 to 2008 to register
|
||||||
|
* This beeing the first singup page, we still don't have any data
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testInputDateMaxYear() {
|
||||||
|
$this->Form->request->data = array();
|
||||||
|
$this->Form->create('User');
|
||||||
|
$result = $this->Form->input('birthday',
|
||||||
|
array(
|
||||||
|
'label' => false,
|
||||||
|
'div' => false,
|
||||||
|
'type' => 'date',
|
||||||
|
'dateFormat' => 'DMY',
|
||||||
|
'minYear' => 2006,
|
||||||
|
'maxYear' => 2008
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->assertContains('value="2008" selected="selected"', $result);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testTextArea method
|
* testTextArea method
|
||||||
*
|
*
|
||||||
|
|
|
@ -2359,7 +2359,11 @@ class FormHelper extends AppHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($attributes['value'] === null && $attributes['empty'] != true) {
|
if ($attributes['value'] === null && $attributes['empty'] != true) {
|
||||||
$attributes['value'] = time();
|
if(!empty($attributes['maxYear']) && $attributes['maxYear'] < date('Y')) {
|
||||||
|
$attributes['value'] = strtotime(date($attributes['maxYear'] . '-m-d'));
|
||||||
|
} else {
|
||||||
|
$attributes['value'] = time();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($attributes['value'])) {
|
if (!empty($attributes['value'])) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue