[web] Add a <label> around choices on CheckBox and Radio form widgets
authorRémi Cardona <remi.cardona@logilab.fr>
Fri, 16 Oct 2015 11:15:50 +0200
changeset 10902 41bd01ebebb4
parent 10901 ddeac3ecdd88
child 10903 da30851f9706
[web] Add a <label> around choices on CheckBox and Radio form widgets Allows clicking directly on the text rather than only on the widget. Closes #7672774.
web/formwidgets.py
web/test/unittest_formwidgets.py
--- a/web/formwidgets.py	Fri Oct 16 10:36:34 2015 +0200
+++ b/web/formwidgets.py	Fri Oct 16 11:15:50 2015 +0200
@@ -618,7 +618,7 @@
                 iattrs['checked'] = u'checked'
             tag = tags.input(name=field.input_name(form, self.suffix),
                              type=self.type, value=value, **iattrs)
-            options.append(u'%s&#160;%s' % (tag, xml_escape(label)))
+            options.append(u'<label>%s&#160;%s</label>' % (tag, xml_escape(label)))
         return sep.join(options)
 
 
--- a/web/test/unittest_formwidgets.py	Fri Oct 16 10:36:34 2015 +0200
+++ b/web/test/unittest_formwidgets.py	Fri Oct 16 11:15:50 2015 +0200
@@ -62,9 +62,9 @@
             field = form.field_by_name('bool')
             widget = field.widget
             self.assertMultiLineEqual(widget._render(form, field, None),
-                '<input id="bool" name="bool" tabindex="1" '
+                '<label><input id="bool" name="bool" tabindex="1" '
                 'type="checkbox" value="1" />&#160;'
-                'python &gt;&gt; others')
+                'python &gt;&gt; others</label>')
 
 
 if __name__ == '__main__':