Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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.
  • Loading branch information...
commit c02b4418bbab61a3c28178e75387d405f742425a 1 parent 06a4e1a
@halkyon halkyon authored
Showing with 19 additions and 3 deletions.
  1. +7 −2 forms/DateField.php
  2. +12 −1 tests/forms/DateFieldTest.php
View
9 forms/DateField.php
@@ -196,8 +196,13 @@ function setValue($val) {
// 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)) {
View
13 tests/forms/DateFieldTest.php
@@ -135,7 +135,18 @@ function testValidateArray() {
// $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)));
Please sign in to comment.
Something went wrong with that request. Please try again.