-
Notifications
You must be signed in to change notification settings - Fork 109
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
Make it easier to set checkbox radio checked options #1105
Make it easier to set checkbox radio checked options #1105
Conversation
Currently you have to set `checked` on each item. This would instead make it possible to set `value` (for radios) or `values` (for checkboxes) which would then automatically set the checked values for the items if they match the value given. The previous method of setting `checked` on each item still works, and would override the default.
In this (or a separate PR) might we also be able to make it so that the first item in the radio or checklist isn’t suffixed with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks ace
Does this fix #988? |
@paulrobertlloyd opps yes, must have forgotten to link the PR to the issue. |
This adds a new param to both the Checkboxes and Radios components to make it easier to set which items should be checked by default.
This behaviour matches the Checkbox and Radios components within GOV.UK Frontend.
Description
Currently to set which radio or checkbox items should be pre-ticked, you have to set a
checked
boolean on the relevant items.When using the NHS prototype kit, this means code like this:
This pull request makes this simpler and less error-prone by allowing you to set the current selected value, and having the nunjucks macro set the matching item as checked, like this:
A similar feature has been added for checkboxes, except that the param is called
values
, and works with an array of values which should be checked:Checklist