mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@97726 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
f2098eaac7
commit
aa27047ed9
@ -103,26 +103,25 @@ class CompositeDateField extends DateField {
|
|||||||
Behaviour.register({
|
Behaviour.register({
|
||||||
"#$formID": {
|
"#$formID": {
|
||||||
validateCompositeDateField: function(fieldName) {
|
validateCompositeDateField: function(fieldName) {
|
||||||
var el = _CURRENT_FORM.elements[fieldName];
|
var day_value = \$F(_CURRENT_FORM.elements[fieldName+'[date]']);
|
||||||
if(!el || !el.value) return true;
|
var month_value = \$F(_CURRENT_FORM.elements[fieldName+'[month]']);
|
||||||
|
var year_value = \$F(_CURRENT_FORM.elements[fieldName+'[year]']);
|
||||||
// Creditcards are split into multiple values, so get the inputs from the form.
|
if(day_value == 'NotSet' && month_value == 'NotSet' && year_value == 'NotSet') return true;
|
||||||
dateParts = $(fieldName).getElementsByTagName('select');
|
else if(day_value == 'NotSet') {
|
||||||
|
var err = "$day";
|
||||||
// Concatenate the string values from the parts of the input.
|
var el = _CURRENT_FORM.elements[fieldName+'[date]'];
|
||||||
for(i=0; i < dateParts.length ; i++ ){
|
} else if(month_value == 'NotSet') {
|
||||||
// The default selected value is 'NotSet'
|
var err = "$month";
|
||||||
if(dateParts[i].value == 'NotSet'){
|
var el = _CURRENT_FORM.elements[fieldName+'[month]'];
|
||||||
switch(i){
|
} else if(year_value == 'NotSet') {
|
||||||
case 0: err = "$day"; break;
|
var err = "$year";
|
||||||
case 1: err = "$month"; break;
|
var el = _CURRENT_FORM.elements[fieldName+'[year]'];
|
||||||
case 2: err = "$year"; break;
|
} else {
|
||||||
}
|
return true;
|
||||||
validationError(dateParts[i],"$error1 '" + err + "' $error2","validation");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
|
validationError(el,"$error1 '" + err + "' $error2","validation");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -72,21 +72,23 @@ HTML;
|
|||||||
function jsValidation() {
|
function jsValidation() {
|
||||||
$formID = $this->form->FormName();
|
$formID = $this->form->FormName();
|
||||||
$error = _t('DateField.VALIDATIONJS', 'Please enter a valid date format (DD/MM/YYYY).');
|
$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
|
$jsFunc =<<<JS
|
||||||
Behaviour.register({
|
Behaviour.register({
|
||||||
"#$formID": {
|
"#$formID": {
|
||||||
validateDMYDate: function(fieldName) {
|
validateDMYDate: function(fieldName) {
|
||||||
var value = \$F(_CURRENT_FORM.elements[fieldName+'[Day]'])
|
var day_value = \$F(_CURRENT_FORM.elements[fieldName+'[Day]']);
|
||||||
+ '/'
|
var month_value = \$F(_CURRENT_FORM.elements[fieldName+'[Month]']);
|
||||||
+ \$F(_CURRENT_FORM.elements[fieldName+'[Month]'])
|
var year_value = \$F(_CURRENT_FORM.elements[fieldName+'[Year]']);
|
||||||
+ '/'
|
if(day_value || month_value || year_value){
|
||||||
+ \$F(_CURRENT_FORM.elements[fieldName+'[Year]'])
|
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}\$/)) {
|
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);
|
validationError(_CURRENT_FORM.elements[fieldName+'[Day]'],"$error","validation",false);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ JS;
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!empty ($this->value) && !preg_match('/^[0-9]{1,2}\/[0-9]{1,2}\/[0-90-9]{2,4}$/', $this->value))
|
if(!empty ($this->value) && is_string($this->value) && !preg_match('/^[0-9]{1,2}\/[0-9]{1,2}\/[0-90-9]{2,4}$/', $this->value))
|
||||||
{
|
{
|
||||||
$validator->validationError(
|
$validator->validationError(
|
||||||
$this->name,
|
$this->name,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user