Skip to content

Commit

Permalink
BUGFIX DateField with setConfig('dmyfields') now validates TRUE for e…
Browse files Browse the repository at this point in the history
…mpty values (fixes #5458)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@103450 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information
chillu authored and Sam Minnee committed Feb 2, 2011
1 parent 219c5ff commit 577857b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion forms/DateField.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ function validate($validator) {

// date format
if($this->getConfig('dmyfields')) {
$valid = ($this->validateArrayValue($this->value));
$valid = (!$this->value || $this->validateArrayValue($this->value));
} else {
$valid = (Zend_Date::isDate($this->value, $this->getConfig('dateformat'), $this->locale));
}
Expand Down
6 changes: 6 additions & 0 deletions tests/forms/DateFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ function testValidateArray() {
$f->setValue(array('day' => 29, 'month' => 03, 'year' => 2003));
$this->assertTrue($f->validate(new RequiredFields()));

$f->setValue(null);
$this->assertTrue($f->validate(new RequiredFields()), 'NULL values are validating TRUE');

$f->setValue(array());
$this->assertTrue($f->validate(new RequiredFields()), 'Empty array values are validating TRUE');

// TODO Fix array validation
// $f = new DateField('Date', 'Date', array('day' => 9999, 'month' => 9999, 'year' => 9999));
// $this->assertFalse($f->validate(new RequiredFields()));
Expand Down

0 comments on commit 577857b

Please sign in to comment.