mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX Empty dmyfields on DateField now validate as true
This commit is contained in:
parent
1a8348900d
commit
f2ed59e185
@ -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')) {
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user