Skip to content
This repository
Browse code

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
Sean Harvey authored March 27, 2012
9  forms/DateField.php
@@ -196,8 +196,13 @@ function setValue($val) {
196 196
 				// Setting in correct locale
197 197
 				if(is_array($val) && $this->validateArrayValue($val)) {
198 198
 					// set() gets confused with custom date formats when using array notation
199  
-					$this->valueObj = new Zend_Date($val, null, $this->locale);
200  
-					$this->value = $this->valueObj->toArray();
  199
+					if(!(empty($val['day']) || empty($val['month']) || empty($val['year']))) {
  200
+						$this->valueObj = new Zend_Date($val, null, $this->locale);
  201
+						$this->value = $this->valueObj->toArray();
  202
+					} else {
  203
+						$this->value = $val;
  204
+						$this->valueObj = null;
  205
+					}
201 206
 				}
202 207
 				// load ISO date from database (usually through Form->loadDataForm())
203 208
 				else if(!empty($val) && Zend_Date::isDate($val, $this->getConfig('datavalueformat'), $this->locale)) {
13  tests/forms/DateFieldTest.php
@@ -135,7 +135,18 @@ function testValidateArray() {
135 135
 		// $f = new DateField('Date', 'Date', array('day' => 9999, 'month' => 9999, 'year' => 9999));
136 136
 		// $this->assertFalse($f->validate(new RequiredFields()));
137 137
 	}
138  
-	
  138
+
  139
+	function testValidateEmptyArrayValuesSetsNullForValueObject() {
  140
+		$f = new DateField('Date', 'Date');
  141
+		$f->setConfig('dmyfields', true);
  142
+
  143
+		$f->setValue(array('day' => '', 'month' => '', 'year' => ''));
  144
+		$this->assertNull($f->dataValue());
  145
+
  146
+		$f->setValue(array('day' => null, 'month' => null, 'year' => null));
  147
+		$this->assertNull($f->dataValue());
  148
+	}
  149
+
139 150
 	function testValidateArrayValue() {
140 151
 		$f = new DateField('Date', 'Date');
141 152
 		$this->assertTrue($f->validateArrayValue(array('day' => 29, 'month' => 03, 'year' => 2003)));

0 notes on commit c02b441

Please sign in to comment.
Something went wrong with that request. Please try again.