mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX: Fixed a number of really basic problems with a number of date fields - got basic loading and saving working across them all
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@62885 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
ed311db3bf
commit
2dcda9bd91
@ -7,7 +7,8 @@
|
||||
class CompositeDateField extends DateField {
|
||||
|
||||
function __construct($name, $title, $value = null, $yearRange = null){
|
||||
list($year,$month, $date) = explode('-', $value);
|
||||
$year = $month = $date = null;
|
||||
if($value) list($year,$month, $date) = explode('-', $value);
|
||||
|
||||
$this->dateDropdown = new DropdownField($name."[date]", "",
|
||||
array('NotSet' => '('._t('CompositeDateField.DAY', 'Day').')',
|
||||
@ -32,7 +33,7 @@ class CompositeDateField extends DateField {
|
||||
);
|
||||
|
||||
if($yearRange == null){
|
||||
$this->customiseYearDropDown($name, "1995-2006", $year);
|
||||
$this->customiseYearDropDown($name, "1995-2012", $year);
|
||||
}else{
|
||||
$this->customiseYearDropDown($name, $yearRange, $year);
|
||||
}
|
||||
|
@ -20,29 +20,34 @@ class DMYCalendarDateField extends CalendarDateField {
|
||||
$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];
|
||||
}
|
||||
|
||||
$dateArray = explode( '-', $val );
|
||||
if($val) {
|
||||
$dateArray = explode( '-', $val );
|
||||
$day = $dateArray[2];
|
||||
$month = $dateArray[1];
|
||||
$year = $dateArray[0];
|
||||
}
|
||||
|
||||
$day = $dateArray[2];
|
||||
$month = $dateArray[1];
|
||||
$year = $dateArray[0];
|
||||
|
||||
preg_match('/(.*)[(.+)]$/', $this->name, $fieldNameParts );
|
||||
|
||||
$fieldNamePrefix = $fieldNameParts[1];
|
||||
$fieldName = $fieldNameParts[2];
|
||||
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}[{$fieldName}-Day]" value="$day" maxlength="2"$tabIndex0 />/
|
||||
<input type="text" id="$id-month" class="month numeric" name="{$fieldNamePrefix}[{$fieldName}-Month]" value="$month" maxlength="2"$tabIndex1 />/
|
||||
<input type="text" id="$id-year" class="year numeric" name="{$fieldNamePrefix}[{$fieldName}-Year]" value="$year" maxlength="4"$tabIndex2 />
|
||||
<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;
|
||||
|
@ -35,11 +35,14 @@ class DMYDateField extends CalendarDateField {
|
||||
$val = $dateArray[2] . '-' . $dateArray[1] . '-' . $dateArray[0];
|
||||
}
|
||||
|
||||
$dateArray = explode( '-', $val );
|
||||
$day = $month = $year = null;
|
||||
if($val) {
|
||||
$dateArray = explode( '-', $val );
|
||||
|
||||
$day = $dateArray[2];
|
||||
$month = $dateArray[1];
|
||||
$year = $dateArray[0];
|
||||
$day = $dateArray[2];
|
||||
$month = $dateArray[1];
|
||||
$year = $dateArray[0];
|
||||
}
|
||||
|
||||
$fieldName = $this->name;
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
class DateField extends TextField {
|
||||
|
||||
function setValue($val) {
|
||||
if($val && preg_match('/^([\d]{2,4})-([\d]{1,2})-([\d]{1,2})/', $val)) {
|
||||
if(is_string($val) && preg_match('/^([\d]{2,4})-([\d]{1,2})-([\d]{1,2})/', $val)) {
|
||||
$this->value = preg_replace('/^([\d]{2,4})-([\d]{1,2})-([\d]{1,2})/','\\3/\\2/\\1', $val);
|
||||
} else {
|
||||
$this->value = $val;
|
||||
@ -17,7 +17,11 @@ class DateField extends TextField {
|
||||
|
||||
function dataValue() {
|
||||
if(is_array($this->value)) {
|
||||
return $this->value['Year'] . '-' . $this->value['Month'] . '-' . $this->value['Day'];
|
||||
if(isset($this->value['Year']) && isset($this->value['Month']) && isset($this->value['Day'])) {
|
||||
return $this->value['Year'] . '-' . $this->value['Month'] . '-' . $this->value['Day'];
|
||||
} else {
|
||||
user_error("Bad DateField value " . var_export($this->value,true), E_USER_WARNING);
|
||||
}
|
||||
} elseif(preg_match('/^([\d]{1,2})\/([\d]{1,2})\/([\d]{2,4})/', $this->value, $parts)) {
|
||||
return "$parts[3]-$parts[2]-$parts[1]";
|
||||
} elseif(!empty($this->value)) {
|
||||
|
Loading…
Reference in New Issue
Block a user