From c4f366b9b94c4ea1af7e964288e41aba914fc5cd Mon Sep 17 00:00:00 2001 From: Elias Showk Date: Wed, 25 Apr 2018 16:26:34 +0200 Subject: [PATCH] add CheckboxesWidget.get_options (#23403) --- wcs/qommon/form.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/wcs/qommon/form.py b/wcs/qommon/form.py index 4e02888e..f9bd9ce4 100644 --- a/wcs/qommon/form.py +++ b/wcs/qommon/form.py @@ -1109,6 +1109,31 @@ class CheckboxesWidget(CompositeWidget): def has_error(self, request=None): return Widget.has_error(self, request=request) + def get_options(self): + options = [] + tags = [] + + if self.options_with_attributes: + options = self.options_with_attributes[:] + + for option in options: + object, description, key = option[:3] + html_attrs = {} + html_attrs['value'] = key + if self.options_with_attributes and option[-1].get('disabled'): + html_attrs['disabled'] = 'disabled' + if self.options_with_attributes and option[-1].get('checked'): + html_attrs['checked'] = 'true' + if description is None: + description = '' + + yield { + 'description': description, + 'key': key, + 'attrs': html_attrs, + 'options': option[-1] if self.options_with_attributes else None + } + class ValidatedStringWidget(StringWidget): '''StringWidget which checks the value entered is correct according to a regex''' -- 2.17.0