BUGFIX Fixed DateField->validate() with keyed, but empty array values

MINOR Fixed DateField/TimeField validation message translation (wrong sprintf() nesting) (from r107789)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112696 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2010-10-18 22:25:41 +00:00
parent 61012967cf
commit c5f4926d4d
5 changed files with 19 additions and 8 deletions

View File

@ -301,14 +301,16 @@ JS;
*/
function validateArrayValue($val) {
if(!is_array($val)) return false;
// Validate against Zend_Date,
// but check for empty array keys (they're included in standard form submissions)
return (
array_key_exists('year', $val)
&& Zend_Date::isDate($val['year'], 'yyyy', $this->locale)
&& (!$val['year'] || Zend_Date::isDate($val['year'], 'yyyy', $this->locale))
&& array_key_exists('month', $val)
&& Zend_Date::isDate($val['month'], 'MM', $this->locale)
&& (!$val['month'] || Zend_Date::isDate($val['month'], 'MM', $this->locale))
&& array_key_exists('day', $val)
&& Zend_Date::isDate($val['day'], 'dd', $this->locale)
&& (!$val['day'] || Zend_Date::isDate($val['day'], 'dd', $this->locale))
);
}
@ -330,7 +332,10 @@ JS;
if(!$valid) {
$validator->validationError(
$this->name,
_t('DateField.VALIDDATEFORMAT2', sprintf("Please enter a valid date format (%s).", $this->getConfig('dateformat'))),
sprintf(
_t('DateField.VALIDDATEFORMAT2', "Please enter a valid date format (%s)."),
$this->getConfig('dateformat')
),
"validation",
false
);

View File

@ -150,7 +150,7 @@ class DatetimeField extends FormField {
function validate($validator) {
$dateValid = $this->dateField->validate($validator);
$timeValid = $this->timeField->validate($validator);
return ($dateValid && $timeValid);
}

View File

@ -146,7 +146,10 @@ class TimeField extends TextField {
if(!Zend_Date::isDate($this->value, $this->getConfig('timeformat'), $this->locale)) {
$validator->validationError(
$this->name,
_t('TimeField.VALIDATEFORMAT', sprintf("Please enter a valid time format (%s)", $this->getConfig('timeformat'))),
sprintf(
_t('TimeField.VALIDATEFORMAT', "Please enter a valid time format (%s)"),
$this->getConfig('timeformat')
),
"validation",
false
);

View File

@ -152,7 +152,7 @@ $lang['en_US']['DateField']['NOTSET'] = 'not set';
$lang['en_US']['DateField']['TODAY'] = 'today';
$lang['en_US']['DateField']['VALIDATIONJS'] = 'Please enter a valid date format (DD/MM/YYYY).';
$lang['en_US']['DateField']['VALIDDATEFORMAT'] = 'Please enter a valid time format.';
$lang['en_US']['DateField']['VALIDDATEFORMAT2'] = 'Please enter a valid time format (%s)';
$lang['en_US']['DateField']['VALIDDATEFORMAT2'] = 'Please enter a valid date format (%s)';
$lang['en_US']['DateField']['VALIDDATEMAXDATE'] = 'Your date has to be older or matching the maximum allowed date (%s)';
$lang['en_US']['DateField']['VALIDDATEMINDATE'] = 'Your date has to be newer or matching the minimum allowed date (%s)';
$lang['en_US']['DropdownField']['CHOOSE'] = array(

View File

@ -125,6 +125,9 @@ class DateFieldTest extends SapphireTest {
$f->setValue(array());
$this->assertTrue($f->validate(new RequiredFields()), 'Empty array values are validating TRUE');
$f->setValue(array('day' => null, 'month' => null, 'year' => null));
$this->assertTrue($f->validate(new RequiredFields()), 'Empty array values with keys 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()));