Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

ENHANCEMENT Passing 'timeformat' and other metadata to markup generat…

…ed in DateField, TimeField and DatetimeField, to allow for easier integration with third party libraries
  • Loading branch information...
commit 7c147fed14dfcccda85f61ac15dfe129f2369cc9 1 parent b807983
@chillu chillu authored
View
52 forms/DateField.php
@@ -55,17 +55,6 @@
* @subpackage fields-datetime
*/
class DateField extends TextField {
-
- /**
- * @var array
- */
- protected static $default_config = array(
- 'showcalendar' => false,
- 'dmyfields' => false,
- 'dmyseparator' => false,
- 'dateformat' => false,
- 'locale' => false
- );
/**
* @var array
@@ -132,6 +121,23 @@ function FieldHolder() {
}
function Field() {
+ $config = array(
+ 'showcalendar' => $this->getConfig('showcalendar'),
+ 'isoDateformat' => $this->getConfig('dateformat'),
+ 'jqueryDateformat' => DateField_View_JQuery::convert_iso_to_jquery_format($this->getConfig('dateformat')),
+ 'min' => $this->getConfig('min'),
+ 'max' => $this->getConfig('max')
+ );
+
+ // Add other jQuery UI specific, namespaced options (only serializable, no callbacks etc.)
+ // TODO Move to DateField_View_jQuery once we have a properly extensible HTML5 attribute system for FormField
+ foreach($this->getConfig() as $k => $v) {
+ if(preg_match('/^jQueryUI\.(.*)/', $k, $matches)) $config[$matches[1]] = $v;
+ }
+
+ $config = array_filter($config);
+ $this->addExtraClass(Convert::raw2json($config));
+
// Three separate fields for day, month and year
if($this->getConfig('dmyfields')) {
// values
@@ -576,31 +582,7 @@ function getField() {
return $this->field;
}
- /**
- *
- */
function onBeforeRender() {
- if($this->getField()->getConfig('showcalendar')) {
- // Inject configuration into existing HTML
- $format = self::convert_iso_to_jquery_format($this->getField()->getConfig('dateformat'));
- $conf = array(
- 'showcalendar' => true,
- 'dateFormat' => $format
- );
- // add min/max to datepicker. ISO format or strtotime() compatible only
- foreach(array('min', 'max') as $type) {
- if($this->getField()->getConfig($type)) {
- $min = new Zend_Date(strtotime($this->getField()->getConfig($type)), null, $this->getField()->locale);
- $conf[$type . 'Date'] = $min->toString($this->getField()->getConfig('dateformat'));
- }
- }
- // Add other namespaced options (only serializable, no callbacks etc.)
- foreach($this->getField()->getConfig() as $k => $v) {
- if(preg_match('/^jQueryUI\.(.*)/', $k, $matches)) $conf[$matches[1]] = $v;
- }
-
- $this->getField()->addExtraClass(str_replace('"', '\'', Convert::raw2json($conf)));
- }
}
/**
View
10 forms/DatetimeField.php
@@ -72,6 +72,16 @@ function setForm($form) {
$this->timezoneField->setForm($form);
}
+ function FieldHolder() {
+ $config = array(
+ 'datetimeorder' => $this->getConfig('datetimeorder'),
+ );
+ $config = array_filter($config);
+ $this->addExtraClass(Convert::raw2json($config));
+
+ return parent::FieldHolder();
+ }
+
function Field() {
Requirements::css(SAPPHIRE_DIR . '/css/DatetimeField.css');
View
9 forms/TimeField.php
@@ -63,6 +63,15 @@ function __construct($name, $title = null, $value = ""){
parent::__construct($name,$title,$value);
}
+ function Field() {
+ $config = array(
+ 'timeformat' => $this->getConfig('timeformat')
+ );
+ $config = array_filter($config);
+ $this->addExtraClass(Convert::raw2json($config));
+ return parent::Field();
+ }
+
/**
* Sets the internal value to ISO date format.
*
View
7 javascript/DateField.js
@@ -9,13 +9,16 @@
fields.siblings("button").addClass("ui-icon ui-icon-calendar");
fields.live('click', function() {
- var holder = $(this).parents('.field.date:first'), config = holder.metadata({type: 'class'});
+ var holder = $(this).parents('.field.date:first'), config = $(this).metadata({type: 'class'});
if(!config.showcalendar) return;
if(config.locale && $.datepicker.regional[config.locale]) {
config = $.extend(config, $.datepicker.regional[config.locale], {});
}
-
+
+ // Initialize and open a datepicker
+ // live() doesn't have "onmatch", and jQuery.entwine is a bit too heavyweight for this, so we need to do this onclick.
+ config.dateFormat = config.jqueryDateformat;
$(this).datepicker(config);
$(this).datepicker('show');
});
Please sign in to comment.
Something went wrong with that request. Please try again.