On Jan 31, 7:58 am, Bernd Rothert <roth...@googlemail.com> wrote: > 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
Hi Bernd & Massimo, Does the above patch ever go into trunk? I see no change in latest source code, perhaps that's why the problem still exists in latest web2py 1.93.2. Background: The web2py book suggests that the default "SQLFORM.widgets.multiple.widget" can be replaced with "SQLFORM.widgets.checkboxes.widget" for list:reference fields. I tried it but the checkboxes did not show any check marks ("because of the int/ string mismatch" according to Bernd). Regards, Iceberg Luo