Implemented feature to allow individual "empty" values for date time select elements

This commit is contained in:
ADmad 2012-07-28 01:47:21 +05:30
parent be59df2e20
commit 99813e97b3
2 changed files with 50 additions and 0 deletions

View file

@ -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
*

View file

@ -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) {