fields: fix display of optional item fields that have no items (#8769)

This commit is contained in:
Frédéric Péters 2015-10-25 11:03:17 +01:00
parent 5c21487c4c
commit e97b4d6233
2 changed files with 13 additions and 1 deletions

View File

@ -173,3 +173,15 @@ def test_item_render():
field.add_to_form(form)
assert str(form.render()).count('<option value="">Bla bla bla</option>') == 1 # ---
assert str(form.render()).count('<option') == 4
# without any item
field = fields.ItemField(id='1', label='Foobar', items=[])
form = Form()
field.add_to_form(form)
assert str(form.render()).count('<option') == 1
# without any item and not being required
field = fields.ItemField(id='1', label='Foobar', items=[], required=False)
form = Form()
field.add_to_form(form)
assert str(form.render()).count('<option') == 1

View File

@ -861,7 +861,7 @@ class ItemField(WidgetField):
options = self.items[:]
else:
options = data_sources.get_items(self.data_source)
if not self.required:
if options and not self.required:
if type(options[0]) is str:
options[:0] = [None]
elif len(options[0]) == 2: