Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support value param for radios #988

Open
frankieroberto opened this issue Jul 19, 2024 · 0 comments
Open

Support value param for radios #988

frankieroberto opened this issue Jul 19, 2024 · 0 comments
Labels
Enhancement: feature request New feature or request

Comments

@frankieroberto
Copy link
Contributor

Currently, if you want to support pre-selecting the right option when going back to a radio field (eg from check your answers), you have to do this:

{{ radios({
  "idPrefix": "example",
  "name": "example",
  "fieldset": {
    "legend": {
      "text": "Are you 18 or over?",
      "classes": "nhsuk-fieldset__legend--l",
      "isPageHeading": true
    }
  },
  "items": [
    {
      "value": "yes",
      "text": "Yes",
      checked: (data.example == "yes")
    },
    {
      "value": "no",
      "text": "No",
      checked: (data.example == "no")
    }
  ]
}) }}

This can be quite long-winded if there are a lot of options.

It’d be easier if we could support a top-level value option which sets the current value (if set), and then checks the right radio option:

{{ radios({
  "idPrefix": "example",
  "name": "example",
  "value": data.example,
  "fieldset": {
    "legend": {
      "text": "Are you 18 or over?",
      "classes": "nhsuk-fieldset__legend--l",
      "isPageHeading": true
    }
  },
  "items": [
    {
      "value": "yes",
      "text": "Yes"
    },
    {
      "value": "no",
      "text": "No"
    }
  ]
}) }}

See code in GOVU.UK Design System for radios

@frankieroberto frankieroberto added the Enhancement: feature request New feature or request label Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement: feature request New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant