mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
BUGFIX: fix front-end validation for DYMCalendarDateField, addressed in open ticket #4967(http://open.silverstripe.org/ticket/4967).
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@97730 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
9ac547d32d
commit
89ccd1cacf
@ -56,5 +56,45 @@ class DMYCalendarDateField extends CalendarDateField {
|
||||
</div>
|
||||
HTML;
|
||||
}
|
||||
|
||||
function jsValidation() {
|
||||
$formID = $this->form->FormName();
|
||||
$error = _t('DateField.VALIDATIONJS', 'Please enter a valid date format (DD/MM/YYYY).');
|
||||
$error = 'Please enter a valid date format (DD/MM/YYYY) from dmy.';
|
||||
$jsFunc =<<<JS
|
||||
Behaviour.register({
|
||||
"#$formID": {
|
||||
validateDMYDate: function(fieldName) {
|
||||
var day_value = \$F(_CURRENT_FORM.elements[fieldName+'[Day]']);
|
||||
var month_value = \$F(_CURRENT_FORM.elements[fieldName+'[Month]']);
|
||||
var year_value = \$F(_CURRENT_FORM.elements[fieldName+'[Year]']);
|
||||
if(day_value || month_value || year_value){
|
||||
var value = day_value + '/' + month_value + '/' + year_value;
|
||||
|
||||
if(value && value.length > 0 && !value.match(/^[0-9]{1,2}\/[0-9]{1,2}\/[0-90-9]{2,4}\$/)) {
|
||||
validationError(_CURRENT_FORM.elements[fieldName+'[Day]'],"$error","validation",false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
JS;
|
||||
Requirements :: customScript($jsFunc, 'func_validateDMYDate_'.$formID);
|
||||
|
||||
// return "\$('$formID').validateDate('$this->name');";
|
||||
return <<<JS
|
||||
if(\$('$formID')){
|
||||
if(typeof fromAnOnBlur != 'undefined'){
|
||||
if(fromAnOnBlur.name == '$this->name')
|
||||
\$('$formID').validateDMYDate('$this->name');
|
||||
}else{
|
||||
\$('$formID').validateDMYDate('$this->name');
|
||||
}
|
||||
}
|
||||
JS;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user