mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX Slice of extra "OO" if SQL server attempts to set value in DateField
BUGFIX Don't attempt to use JS validation on DateField is javascript handler is "none" git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@78065 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
a338a8d6a9
commit
ee2771e99a
@ -20,6 +20,18 @@ class DateField extends TextField {
|
|||||||
public static $validation_enabled = true;
|
public static $validation_enabled = true;
|
||||||
|
|
||||||
function setValue($val) {
|
function setValue($val) {
|
||||||
|
if ($val) {
|
||||||
|
if (!is_array($val) ) { //&& strlen($val) == 26) {
|
||||||
|
|
||||||
|
$ampm = substr($val,strlen($val)-2,strlen($val));
|
||||||
|
if ($ampm == "PM") { //correct for pm offset when cutting off 12-hour clock format
|
||||||
|
$val = substr($val,0,strlen($val)-6)."PM";
|
||||||
|
} elseif ($ampm == "AM") {
|
||||||
|
$val = substr($val,0,strlen($val)-6);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(is_string($val) && preg_match('/^([\d]{2,4})-([\d]{1,2})-([\d]{1,2})/', $val)) {
|
if(is_string($val) && preg_match('/^([\d]{2,4})-([\d]{1,2})-([\d]{1,2})/', $val)) {
|
||||||
$this->value = preg_replace('/^([\d]{2,4})-([\d]{1,2})-([\d]{1,2})/','\\3/\\2/\\1', $val);
|
$this->value = preg_replace('/^([\d]{2,4})-([\d]{1,2})-([\d]{1,2})/','\\3/\\2/\\1', $val);
|
||||||
} else {
|
} else {
|
||||||
@ -51,7 +63,12 @@ class DateField extends TextField {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function jsValidation() {
|
function jsValidation() {
|
||||||
$formID = $this->form->FormName();
|
$formID = $this->form->FormName();
|
||||||
|
|
||||||
|
if(Validator::get_javascript_validator_handler() == 'none') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
$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).');
|
||||||
$jsFunc =<<<JS
|
$jsFunc =<<<JS
|
||||||
Behaviour.register({
|
Behaviour.register({
|
||||||
@ -85,7 +102,9 @@ JS;
|
|||||||
}
|
}
|
||||||
|
|
||||||
function validate($validator) {
|
function validate($validator) {
|
||||||
if(!self::$validation_enabled) {
|
$validationHandler = Validator::get_javascript_validator_handler();
|
||||||
|
|
||||||
|
if(!self::$validation_enabled || $validationHandler == 'none') {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user