mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Implemented feature to allow individual "empty" values for date time select elements
This commit is contained in:
parent
be59df2e20
commit
99813e97b3
2 changed files with 50 additions and 0 deletions
|
@ -5124,6 +5124,45 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertNotRegExp('/selected="selected">\d/', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testDateTimeEmptyAsArray
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDateTimeEmptyAsArray() {
|
||||
$result = $this->Form->dateTime('Contact.date',
|
||||
'DMY',
|
||||
'12',
|
||||
array(
|
||||
'empty' => array('day' => 'DAY', 'month' => 'MONTH', 'year' => 'YEAR',
|
||||
'hour' => 'HOUR', 'minute' => 'MINUTE', 'meridian' => false
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertRegExp('/<option value="">DAY<\/option>/', $result);
|
||||
$this->assertRegExp('/<option value="">MONTH<\/option>/', $result);
|
||||
$this->assertRegExp('/<option value="">YEAR<\/option>/', $result);
|
||||
$this->assertRegExp('/<option value="">HOUR<\/option>/', $result);
|
||||
$this->assertRegExp('/<option value="">MINUTE<\/option>/', $result);
|
||||
$this->assertNotRegExp('/<option value=""><\/option>/', $result);
|
||||
|
||||
$result = $this->Form->dateTime('Contact.date',
|
||||
'DMY',
|
||||
'12',
|
||||
array(
|
||||
'empty' => array('day' => 'DAY', 'month' => 'MONTH', 'year' => 'YEAR')
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertRegExp('/<option value="">DAY<\/option>/', $result);
|
||||
$this->assertRegExp('/<option value="">MONTH<\/option>/', $result);
|
||||
$this->assertRegExp('/<option value="">YEAR<\/option>/', $result);
|
||||
$this->assertRegExp('/<select[^<>]+id="ContactDateHour">\s<option value=""><\/option>/', $result);
|
||||
$this->assertRegExp('/<select[^<>]+id="ContactDateMin">\s<option value=""><\/option>/', $result);
|
||||
$this->assertRegExp('/<select[^<>]+id="ContactDateMeridian">\s<option value=""><\/option>/', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testFormDateTimeMulti method
|
||||
*
|
||||
|
|
|
@ -2259,6 +2259,17 @@ class FormHelper extends AppHelper {
|
|||
}
|
||||
}
|
||||
|
||||
if (is_array($attributes['empty'])) {
|
||||
$attributes['empty'] += array(
|
||||
'month' => true, 'year' => true, 'day' => true,
|
||||
'hour' => true, 'minute' => true, 'meridian' => true
|
||||
);
|
||||
foreach ($elements as $element) {
|
||||
$selectAttrName = 'select' . $element . 'Attr';
|
||||
${$selectAttrName}['empty'] = $attributes['empty'][strtolower($element)];
|
||||
}
|
||||
}
|
||||
|
||||
$selects = array();
|
||||
foreach (preg_split('//', $dateFormat, -1, PREG_SPLIT_NO_EMPTY) as $char) {
|
||||
switch ($char) {
|
||||
|
|
Loading…
Reference in a new issue