mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX Fixed DateField->validate() with keyed, but empty array values
MINOR Fixed DateField/TimeField validation message translation (wrong sprintf() nesting) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@107789 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
2a81458134
commit
e8cc316c1a
@ -301,14 +301,16 @@ JS;
|
|||||||
*/
|
*/
|
||||||
function validateArrayValue($val) {
|
function validateArrayValue($val) {
|
||||||
if(!is_array($val)) return false;
|
if(!is_array($val)) return false;
|
||||||
|
|
||||||
|
// Validate against Zend_Date,
|
||||||
|
// but check for empty array keys (they're included in standard form submissions)
|
||||||
return (
|
return (
|
||||||
array_key_exists('year', $val)
|
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)
|
&& 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)
|
&& 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) {
|
if(!$valid) {
|
||||||
$validator->validationError(
|
$validator->validationError(
|
||||||
$this->name,
|
$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",
|
"validation",
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
@ -150,7 +150,7 @@ class DatetimeField extends FormField {
|
|||||||
function validate($validator) {
|
function validate($validator) {
|
||||||
$dateValid = $this->dateField->validate($validator);
|
$dateValid = $this->dateField->validate($validator);
|
||||||
$timeValid = $this->timeField->validate($validator);
|
$timeValid = $this->timeField->validate($validator);
|
||||||
|
|
||||||
return ($dateValid && $timeValid);
|
return ($dateValid && $timeValid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +146,10 @@ class TimeField extends TextField {
|
|||||||
if(!Zend_Date::isDate($this->value, $this->getConfig('timeformat'), $this->locale)) {
|
if(!Zend_Date::isDate($this->value, $this->getConfig('timeformat'), $this->locale)) {
|
||||||
$validator->validationError(
|
$validator->validationError(
|
||||||
$this->name,
|
$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",
|
"validation",
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
@ -152,7 +152,7 @@ $lang['en_US']['DateField']['NOTSET'] = 'not set';
|
|||||||
$lang['en_US']['DateField']['TODAY'] = 'today';
|
$lang['en_US']['DateField']['TODAY'] = 'today';
|
||||||
$lang['en_US']['DateField']['VALIDATIONJS'] = 'Please enter a valid date format (DD/MM/YYYY).';
|
$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']['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']['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']['DateField']['VALIDDATEMINDATE'] = 'Your date has to be newer or matching the minimum allowed date (%s)';
|
||||||
$lang['en_US']['DropdownField']['CHOOSE'] = array(
|
$lang['en_US']['DropdownField']['CHOOSE'] = array(
|
||||||
|
@ -125,6 +125,9 @@ class DateFieldTest extends SapphireTest {
|
|||||||
$f->setValue(array());
|
$f->setValue(array());
|
||||||
$this->assertTrue($f->validate(new RequiredFields()), 'Empty array values are validating TRUE');
|
$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
|
// TODO Fix array validation
|
||||||
// $f = new DateField('Date', 'Date', array('day' => 9999, 'month' => 9999, 'year' => 9999));
|
// $f = new DateField('Date', 'Date', array('day' => 9999, 'month' => 9999, 'year' => 9999));
|
||||||
// $this->assertFalse($f->validate(new RequiredFields()));
|
// $this->assertFalse($f->validate(new RequiredFields()));
|
||||||
|
Loading…
Reference in New Issue
Block a user