silverstripe-framework/forms/DMYCalendarDateField.php
Ingo Schommer b1baa84efb ENHANCEMENT Using jQuery UI datepicker in CalendarDateField
API CHANGE Removed javascript datepicker functionality in DMYCalendarDateField

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@92512 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-11-21 02:30:31 +00:00

52 lines
1.5 KiB
PHP
Executable File

<?php
/**
* Displays a date field with day, month and year boxes, with a calendar to select
* the date.
*
* @todo Add localization support, see http://open.silverstripe.com/ticket/2931
*
* @package forms
* @subpackage fields-datetime
*/
class DMYCalendarDateField extends CalendarDateField {
function Field() {
$field = DateField::Field();
$id = $this->id();
$val = $this->attrValue();
$day = $month = $year = null;
if( preg_match( '/^\d{2}\/\d{2}\/\d{4}$/', $val ) ) {
$dateArray = explode( '/', $val );
$val = $dateArray[2] . '-' . $dateArray[1] . '-' . $dateArray[0];
}
if($val) {
$dateArray = explode( '-', $val );
$day = $dateArray[2];
$month = $dateArray[1];
$year = $dateArray[0];
}
if(preg_match('/(.*)[(.+)]$/', $this->name, $fieldNameParts)) {
$fieldNamePrefix = $fieldNameParts[1];
$fieldName = $fieldNameParts[2];
} else {
$fieldNamePrefix = $this->name;
$fieldName = $this->name;
}
return <<<HTML
<div class="dmycalendardate">
<input type="hidden" id="$id" name="{$this->name}" value="$val" />
<input type="text" id="$id-day" class="day numeric" name="{$fieldNamePrefix}[Day]" value="$day" maxlength="2" />/
<input type="text" id="$id-month" class="month numeric" name="{$fieldNamePrefix}[Month]" value="$month" maxlength="2" />/
<input type="text" id="$id-year" class="year numeric" name="{$fieldNamePrefix}[Year]" value="$year" maxlength="4" />
<div class="calendarpopup" id="{$id}-calendar"></div>
</div>
HTML;
}
}
?>