LandRegistry / govuk-frontend-wtf

GOV.UK Frontend WTForms Widgets
https://pypi.org/project/govuk-frontend-wtf/
MIT License
17 stars 7 forks source link

Cannot set fieldset on GovCheckboxInput #89

Open markhobson opened 7 months ago

markhobson commented 7 months ago

Describe the bug The GovCheckboxInput widget assumes that a fieldset is never used for a single checkbox. This can be useful for confirmation questions, e.g.:

Are these answers correct?
[x] I confirm that all answers are correct

To Reproduce

>>> from wtforms import BooleanField, Form
>>> from govuk_frontend_wtf.wtforms_widgets import GovCheckboxInput
>>> class MyForm(Form):
...     boolean = BooleanField(widget=GovCheckboxInput())
>>> form = MyForm()
>>> form.boolean.widget.map_gov_params(form.boolean, params={"fieldset": {"legend": {"text": "mylegend"}}}, items=[])
{'name': 'boolean', 'items': [], 'hint': {'text': ''}}

Expected behavior I would expected the supplied fieldset to be preserved:

{'name': 'boolean', 'items': [], 'hint': {'text': ''}, 'fieldset': {'legend': {'text': 'mylegend'}}}

This behaviour is due to GovCheckboxInput trying to remove the default fieldset added by its superclass, GovCheckboxesInput.