From 0c5c5ffb2cd22a307d5243daa765dd60763cb6c9 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Thu, 22 Mar 2012 16:34:45 +0000 Subject: [PATCH] Handle custom field date formatting --- .../inc/class.etemplate_widget_customfields.inc.php | 9 +++++++++ etemplate/js/et2_extension_customfields.js | 13 +++++++++++++ 2 files changed, 22 insertions(+) diff --git a/etemplate/inc/class.etemplate_widget_customfields.inc.php b/etemplate/inc/class.etemplate_widget_customfields.inc.php index 4b98055540..fba1acfa84 100644 --- a/etemplate/inc/class.etemplate_widget_customfields.inc.php +++ b/etemplate/inc/class.etemplate_widget_customfields.inc.php @@ -184,5 +184,14 @@ class etemplate_widget_customfields extends etemplate_widget_transformer $this->setElementAttribute($form_name, 'customfields', $fields); } parent::beforeSendToClient($cname); + + // Re-format date custom fields from Y-m-d + foreach($fields as $fname => $field) + { + if($field['type'] == 'date' && self::$request->content[self::$prefix.$fname]) + { + self::$request->content[self::$prefix.$fname] = strtotime(self::$request->content[self::$prefix.$fname]); + } + } } } diff --git a/etemplate/js/et2_extension_customfields.js b/etemplate/js/et2_extension_customfields.js index 26b9eafb7c..7d5057ae4d 100644 --- a/etemplate/js/et2_extension_customfields.js +++ b/etemplate/js/et2_extension_customfields.js @@ -261,6 +261,19 @@ var et2_customfields_list = et2_baseWidget.extend([et2_IDetachedDOM], { // Make sure widget is created, and has the needed function if(!this.widgets[field_name] || !this.widgets[field_name].set_value) continue; var value = _value[this.prefix + field_name] ? _value[this.prefix + field_name] : null; + + switch(this.options.customfields[field_name].type) + { + case 'date': + // Date custom fields are always in Y-m-d, which seldom matches user's preference + // which fails when sent to date widget. This is only used for nm rows, when possible + // this is fixed server side + if(value && isNaN(value)) + { + value = jQuery.datepicker.parseDate("yy-mm-dd",value); + } + break; + } this.widgets[field_name].set_value(value); } },