Commit 03d4636a authored by Yoshinori Okuji's avatar Yoshinori Okuji

Take it into account that MultiItemsWidget can have multiple default values....

Take it into account that MultiItemsWidget can have multiple default values. Use an index instead of a value as a dict key for safety.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@1369 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4a45a2a1
...@@ -162,7 +162,12 @@ def MultiSelectionValidator_validate(self, field, key, REQUEST): ...@@ -162,7 +162,12 @@ def MultiSelectionValidator_validate(self, field, key, REQUEST):
item_text = item item_text = item
item_value = item item_value = item
value_dict[item_value] = 0 value_dict[item_value] = 0
value_dict[field.get_value('default', cell=getattr(REQUEST,'cell',None))] = 0 default_value = field.get_value('default', cell=getattr(REQUEST,'cell',None))
if type(default_value) in (type([]), type(())):
for v in default_value:
value_dict[v] = 0
else:
value_dict[default_value] = 0
# check whether all values are in dictionary # check whether all values are in dictionary
...@@ -435,7 +440,7 @@ def MultiItemsWidget_render_items(self, field, key, value, REQUEST): ...@@ -435,7 +440,7 @@ def MultiItemsWidget_render_items(self, field, key, value, REQUEST):
value = [value] value = [value]
# XXX -yo # XXX -yo
selected_found = dict.fromkeys(value, 0) selected_found = {}
items = field.get_value('items',REQUEST=REQUEST) # The only thing changes, added request items = field.get_value('items',REQUEST=REQUEST) # The only thing changes, added request
css_class = field.get_value('css_class') css_class = field.get_value('css_class')
...@@ -455,7 +460,8 @@ def MultiItemsWidget_render_items(self, field, key, value, REQUEST): ...@@ -455,7 +460,8 @@ def MultiItemsWidget_render_items(self, field, key, value, REQUEST):
css_class, css_class,
extra_item) extra_item)
# XXX -yo # XXX -yo
selected_found[tuple(value)] = 1 index = value.index(item_value)
selected_found[index] = 1
else: else:
rendered_item = self.render_item(item_text, rendered_item = self.render_item(item_text,
item_value, item_value,
...@@ -466,8 +472,9 @@ def MultiItemsWidget_render_items(self, field, key, value, REQUEST): ...@@ -466,8 +472,9 @@ def MultiItemsWidget_render_items(self, field, key, value, REQUEST):
rendered_items.append(rendered_item) rendered_items.append(rendered_item)
# XXX We want to make sure that we always have the current value in items. -yo # XXX We want to make sure that we always have the current value in items. -yo
for v in value: for index in range(len(value)):
if not selected_found[tuple(v)] and v: v = value[index]
if index not in selected_found and v:
rendered_item = self.render_selected_item('??? (%s)' % v, rendered_item = self.render_selected_item('??? (%s)' % v,
v, v,
key, key,
......
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