Skip to content

GovCheckbox(es)Input renders "None" hint #112

@samuelhwilliams

Description

@samuelhwilliams

Describe the bug
GovCheckboxInput (at least, probably also GovCheckboxesInput?) is rendering None hints for me. This seems tied back to https://github.com/LandRegistry/govuk-frontend-wtf/blob/main/govuk_frontend_wtf/gov_form_base.py#L109, where we always include a "hint" object based on field.description. If field.description is None, we pass through "hint": {"text": None}. The macro for GovCheckboxes then looks for if params.hint, which will evaluate as truthy.

There are two places to fix this, I guess:

  1. govuk-frontend-jinja: check for if params.hint and (params.hint.text or params.hint.html), or similar.
  2. govuk-frontend-wtf: in map_gov_params, only set hint if field.description is truth-y.

To Reproduce
Steps to reproduce the behavior:

  1. Create a wtform with a BooleanField using GovCheckboxInput. Do not pass a description to the field.
  2. Render it on the page.
  3. Check HTML and see that we still render the hint, but it's empty
  4. Change the form to pass description=None; reload the page and you'll see None is shown as text in the hint.

Expected behavior
An empty hint text ("" or None) does not render on the page.

Screenshots

Image Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions