[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.
--- 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 %s' % (tag, xml_escape(label)))
+ options.append(u'<label>%s %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" /> '
- 'python >> others')
+ 'python >> others</label>')
if __name__ == '__main__':