From 3d581e4b7d3491bfb77310d6288c3716b65728a2 Mon Sep 17 00:00:00 2001
From: Yoshinori Okuji <yo@nexedi.com>
Date: Sun, 6 Feb 2005 13:59:10 +0000
Subject: [PATCH] Extra check for DateField if used in ListBox

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@2418 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Form/FormulatorPatch.py | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/product/ERP5Form/FormulatorPatch.py b/product/ERP5Form/FormulatorPatch.py
index fe6e1a229d..713cbf953d 100755
--- a/product/ERP5Form/FormulatorPatch.py
+++ b/product/ERP5Form/FormulatorPatch.py
@@ -522,3 +522,21 @@ def MultiItemsWidget_render_items(self, field, key, value, REQUEST):
 
 MultiItemsWidget.render_items = MultiItemsWidget_render_items
 
+# JPS - Subfield handling with listbox requires extension
+
+from Products.Formulator.StandardFields import DateTimeField
+
+class PatchedDateTimeField(DateTimeField):
+  def _get_default(self, key, value, REQUEST):
+    if value is not None:
+        return value
+    # if there is something in the request then return None
+    # sub fields should pick up defaults themselves
+    if REQUEST is not None and hasattr(REQUEST, 'form') and \
+       REQUEST.form.has_key('subfield_%s_%s' % (self.id, 'year')):
+        return None
+    else:
+        return self.get_value('default')
+
+DateTimeField._get_default = PatchedDateTimeField._get_default
+
-- 
2.30.9