FEATURE: added ability to define a default configuration set for date field. PATCH via gigtech. Fixes (#6131).

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@114816 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Will Rossiter 2010-12-11 02:26:59 +00:00
parent 21f84c9513
commit 1ca5ea6fb4

View File

@ -47,6 +47,17 @@ require_once 'Zend/Date.php';
*/ */
class DateField extends TextField { class DateField extends TextField {
/**
* @var array
*/
protected static $default_config = array(
'showcalendar' => false,
'dmyfields' => false,
'dmyseparator' => false,
'dateformat' => false,
'locale' => false
);
/** /**
* @var array * @var array
*/ */
@ -82,6 +93,15 @@ class DateField extends TextField {
$this->setConfig('dateformat', i18n::get_date_format()); $this->setConfig('dateformat', i18n::get_date_format());
} }
foreach (self::$default_config AS $defaultK => $defaultV) {
if ($defaultV) {
if ($defaultK=='locale')
$this->locale = $defaultV;
else
$this->setConfig($defaultK, $defaultV);
}
}
parent::__construct($name, $title, $value, $form, $rightTitle); parent::__construct($name, $title, $value, $form, $rightTitle);
} }
@ -321,6 +341,19 @@ JS;
); );
} }
/**
* @param String $k
* @param mixed $v
* @return boolean
*/
static function set_default_config($k, $v) {
if (array_key_exists($k,self::$default_config)) {
self::$default_config[$k]=$v;
return true;
}
return false;
}
/** /**
* @return Boolean * @return Boolean
*/ */