Skip to content

Commit

Permalink
Implemented feature to allow individual "empty" values for date time …
Browse files Browse the repository at this point in the history
…select elements
  • Loading branch information
ADmad committed Jul 27, 2012
1 parent be59df2 commit 99813e9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
39 changes: 39 additions & 0 deletions lib/Cake/Test/Case/View/Helper/FormHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5124,6 +5124,45 @@ public function testDateTimeWithBogusData() {
$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
*
Expand Down
11 changes: 11 additions & 0 deletions lib/Cake/View/Helper/FormHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2259,6 +2259,17 @@ public function dateTime($fieldName, $dateFormat = 'DMY', $timeFormat = '12', $a
}
}

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) {
Expand Down

0 comments on commit 99813e9

Please sign in to comment.