This patch fixes the CheckboxesWidget as a replacement for the
MultipleOptionsWidget in "list:reference" fields.

"list:reference" fields use the IS_IN_DB(...,multiple=True) validator. Its
options() method returns possible choices a list of string tuples (<key>,
<label>) to be used in HTML option tags and checkboxes. So the widget has to
convert the current values of the reference field to strings as well before
comparing them to the string <key>s returned by options() - see "value=(k in
values)".

Without the conversion the checkboxes won't show the current values - there
won't be any check marks.


diff -r 6e655c2a202d gluon/sqlhtml.py
--- a/gluon/sqlhtml.py  Sat Jan 29 22:49:21 2011 -0600
+++ b/gluon/sqlhtml.py  Sun Jan 30 22:53:07 2011 +0100
@@ -328,7 +328,10 @@
         """

         # was values = re.compile('[\w\-:]+').findall(str(value))
-        values = not isinstance(value,(list,tuple)) and [value] or value
+        if isinstance(value, (list, tuple)):
+            values = [str(v) for v in value]
+        else:
+            values = [str(value)]

         attr = OptionsWidget._attributes(field, {}, **attributes)


Cheers
Bernd

Reply via email to