Commit 8493bb16 authored by Jérome Perrin's avatar Jérome Perrin

Listbox: Use an hidden field so that validator knows that listbox was empty

This way validator scripts will be called even for empty listboxs, and this
should also remove ERP5Form/Form.py:validate_all KeyError : 'Field listbox is
not present in request object.' messages from the logs
parent 7567efe0
...@@ -503,6 +503,8 @@ ...@@ -503,6 +503,8 @@
<span i18n:translate="" i18n:domain="ui">\n <span i18n:translate="" i18n:domain="ui">\n
No result.\n No result.\n
</span>\n </span>\n
<input type="hidden" value="1" name="listbox_empty:boolean"\n
tal:attributes="name string:${field_prefix}${field_id}_empty:boolean" />\n
</td>\n </td>\n
</tr>\n </tr>\n
</tbody>\n </tbody>\n
......
1089 1090
\ No newline at end of file \ No newline at end of file
...@@ -2762,11 +2762,15 @@ class ListBoxValidator(Validator.Validator): ...@@ -2762,11 +2762,15 @@ class ListBoxValidator(Validator.Validator):
result = {} result = {}
error_result = {} error_result = {}
try: listbox_empty = REQUEST.get('%s_empty' % field.id, False)
listbox_uids = REQUEST['%s_uid' % field.id] if listbox_empty:
except KeyError: listbox_uids = []
raise KeyError('Field %s is not present in request object.' else:
% field.id) try:
listbox_uids = REQUEST['%s_uid' % field.id]
except KeyError:
raise KeyError('Field %s is not present in request object.'
% field.id)
select = field.get_value('select') select = field.get_value('select')
if select: if select:
selected_uid_set = set(REQUEST.get('uids', ())) selected_uid_set = set(REQUEST.get('uids', ()))
......
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