mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX Using DateField "dmyfields" option, if you set empty
day/month/year values, valueObj on DateField will contain erroneous values. Check that all the value inputs aren't null or empty values BEFORE calling Zend_Date on the value.
This commit is contained in:
parent
06a4e1aad6
commit
c02b4418bb
@ -196,8 +196,13 @@ class DateField extends TextField {
|
||||
// Setting in correct locale
|
||||
if(is_array($val) && $this->validateArrayValue($val)) {
|
||||
// set() gets confused with custom date formats when using array notation
|
||||
$this->valueObj = new Zend_Date($val, null, $this->locale);
|
||||
$this->value = $this->valueObj->toArray();
|
||||
if(!(empty($val['day']) || empty($val['month']) || empty($val['year']))) {
|
||||
$this->valueObj = new Zend_Date($val, null, $this->locale);
|
||||
$this->value = $this->valueObj->toArray();
|
||||
} else {
|
||||
$this->value = $val;
|
||||
$this->valueObj = null;
|
||||
}
|
||||
}
|
||||
// load ISO date from database (usually through Form->loadDataForm())
|
||||
else if(!empty($val) && Zend_Date::isDate($val, $this->getConfig('datavalueformat'), $this->locale)) {
|
||||
|
@ -135,7 +135,18 @@ class DateFieldTest extends SapphireTest {
|
||||
// $f = new DateField('Date', 'Date', array('day' => 9999, 'month' => 9999, 'year' => 9999));
|
||||
// $this->assertFalse($f->validate(new RequiredFields()));
|
||||
}
|
||||
|
||||
|
||||
function testValidateEmptyArrayValuesSetsNullForValueObject() {
|
||||
$f = new DateField('Date', 'Date');
|
||||
$f->setConfig('dmyfields', true);
|
||||
|
||||
$f->setValue(array('day' => '', 'month' => '', 'year' => ''));
|
||||
$this->assertNull($f->dataValue());
|
||||
|
||||
$f->setValue(array('day' => null, 'month' => null, 'year' => null));
|
||||
$this->assertNull($f->dataValue());
|
||||
}
|
||||
|
||||
function testValidateArrayValue() {
|
||||
$f = new DateField('Date', 'Date');
|
||||
$this->assertTrue($f->validateArrayValue(array('day' => 29, 'month' => 03, 'year' => 2003)));
|
||||
|
Loading…
Reference in New Issue
Block a user