Commit 4fa84233 authored by Arnaud Fontaine's avatar Arnaud Fontaine

ERP5Form: Returned field default value for ListBox was not consistent with non-ListBox field.

So, Relation Fields in ListBox were ignored during validation as the input
value is compared with the current (default), thus the field could not be
cleared as the value from the actual object was not retrieved at all.
parent 48b9e09a
......@@ -255,13 +255,14 @@ class OverrideValue(StaticValue):
class DefaultValue(StaticValue):
def __init__(self, field_id, value):
self.key = field_id[3:]
self.key = field_id.split('_', 1)[1]
self.value = value
def __call__(self, field, id, **kw):
REQUEST = get_request()
try:
form = field.aq_parent
ob = getattr(form, 'aq_parent', None)
ob = REQUEST.get('cell', getattr(form, 'aq_parent', None))
value = self.value
try:
if value not in (None, ''):
......@@ -337,7 +338,8 @@ def getFieldValue(self, field, id, **kw):
field_id = field.id
if id == 'default' and field_id.startswith('my_'):
if id == 'default' and (field_id.startswith('my_') or
field_id.startswith('listbox_')):
if field.meta_type == 'ProxyField' and \
field.getRecursiveTemplateField().meta_type == 'CheckBoxField' or \
self.meta_type == 'CheckBoxField':
......
......@@ -679,7 +679,8 @@ class ProxyField(ZMIField):
value = copyMethod(value)
cacheable = isCacheable(value)
if id == 'default' and field_id.startswith('my_'):
if id == 'default' and (field_id.startswith('my_') or
field_id.startswith('listbox_')):
# XXX far from object-oriented programming
if template_field.meta_type == 'CheckBoxField':
return DefaultCheckBoxValue(field_id, value), cacheable
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment