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:
Sean Harvey 2009-03-10 02:32:42 +00:00
parent c5d1a53281
commit 41aac525b5

View File

@ -7,6 +7,15 @@
*/ */
class DateField extends TextField { 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) { function setValue($val) {
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);
@ -72,8 +81,11 @@ if(\$('$formID')){
JS; 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)) if(!empty ($this->value) && !preg_match('/^[0-9]{1,2}\/[0-9]{1,2}\/[0-90-9]{2,4}$/', $this->value))
{ {
$validator->validationError( $validator->validationError(