diff --git a/forms/DateField.php b/forms/DateField.php index 3c2d26af2..e8a182f13 100644 --- a/forms/DateField.php +++ b/forms/DateField.php @@ -340,7 +340,14 @@ class DateField extends TextField { $valid = true; // Don't validate empty fields - if(empty($this->value)) return true; + if ($this->getConfig('dmyfields')) { + if (empty($this->value['day']) && empty($this->value['month']) && empty($this->value['year'])) { + return $valid; + } + } + elseif (empty($this->value)) { + return $valid; + } // date format if($this->getConfig('dmyfields')) { diff --git a/tests/forms/DateFieldTest.php b/tests/forms/DateFieldTest.php index 2a27de786..a5a861ac5 100644 --- a/tests/forms/DateFieldTest.php +++ b/tests/forms/DateFieldTest.php @@ -115,6 +115,21 @@ class DateFieldTest extends SapphireTest { $f = new DateField('Date', 'Date', 'wrong'); $this->assertFalse($f->validate(new RequiredFields())); + + } + + public function testEmptyValueValidation() { + $field = new DateField('Date'); + $validator = new RequiredFields(); + $this->assertTrue($field->validate($validator)); + $field->setConfig('dmyfields', true); + $this->assertTrue($field->validate($validator)); + $field->setValue(array( + 'day' => '', + 'month' => '', + 'year' => '', + )); + $this->assertTrue($field->validate($validator)); } public function testValidateArray() {