Merge pull request #5937 from dhensby/pulls/3.4/fix-empty-dmyfields-validation

FIX Empty dmyfields on DateField now validate as true
This commit is contained in:
Damian Mooyman 2016-09-02 09:01:39 +12:00 committed by GitHub
commit a68dfd1016
2 changed files with 23 additions and 1 deletions

View File

@ -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')) {

View File

@ -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() {