mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
ENHANCEMENT DateField validation is now enabled through DateField::$validation_enabled so that it can be optionally disabled by setting it to false
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@72753 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
c5d1a53281
commit
41aac525b5
@ -7,6 +7,15 @@
|
||||
*/
|
||||
class DateField extends TextField {
|
||||
|
||||
/**
|
||||
* Enable DD/MM/YYYY field format validation
|
||||
* in {@link DateField->validate()}. Set to
|
||||
* FALSE to disable this validation.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public static $validation_enabled = true;
|
||||
|
||||
function setValue($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);
|
||||
@ -72,8 +81,11 @@ if(\$('$formID')){
|
||||
JS;
|
||||
}
|
||||
|
||||
function validate($validator)
|
||||
{
|
||||
function validate($validator) {
|
||||
if(!self::$validation_enabled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!empty ($this->value) && !preg_match('/^[0-9]{1,2}\/[0-9]{1,2}\/[0-90-9]{2,4}$/', $this->value))
|
||||
{
|
||||
$validator->validationError(
|
||||
|
Loading…
x
Reference in New Issue
Block a user