FIX Empty dmyfields on DateField now validate as true

This commit is contained in:
Daniel Hensby 2016-09-01 11:39:46 +01:00
parent 1a8348900d
commit f2ed59e185
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E
2 changed files with 23 additions and 1 deletions

View File

@ -340,7 +340,14 @@ class DateField extends TextField {
$valid = true; $valid = true;
// Don't validate empty fields // 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 // date format
if($this->getConfig('dmyfields')) { if($this->getConfig('dmyfields')) {

View File

@ -115,6 +115,21 @@ class DateFieldTest extends SapphireTest {
$f = new DateField('Date', 'Date', 'wrong'); $f = new DateField('Date', 'Date', 'wrong');
$this->assertFalse($f->validate(new RequiredFields())); $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() { public function testValidateArray() {