Radios
Read more about the
radios
component on the Gov.UK Design System website
@using GovUkDesignSystemDotNet
@await Html.GovUkRadios(new RadiosViewModel
{
Name = "where-do-you-live",
Fieldset = new FieldsetViewModel
{
Legend = new FieldsetLegendViewModel
{
HtmlOrText = new HtmlOrText("Where do you live?"),
IsPageHeading = true,
Classes = ["govuk-fieldset__legend--l"]
}
},
RadioItems = new List<RadioItemViewModel>
{
new RadioItemViewModel
{
Value = "england",
Label = new LabelViewModel
{
HtmlOrText = new HtmlOrText("England")
}
},
new RadioItemViewModel
{
Value = "scotland",
Label = new LabelViewModel
{
HtmlOrText = new HtmlOrText("Scotland")
}
},
new RadioItemViewModel
{
Value = "wales",
Label = new LabelViewModel
{
HtmlOrText = new HtmlOrText("Wales")
}
},
new RadioItemViewModel
{
Value = "northern-ireland",
Label = new LabelViewModel
{
HtmlOrText = new HtmlOrText("Northern Ireland")
}
},
}
})
Options
Options for RadiosViewModel
|
List<string>
|
One or more element IDs to add to the input aria-describedby attribute,
used to provide additional descriptive information for screenreader users.
|
|
FieldsetViewModel
|
Can be used to add a fieldset to the radios component.
See options for FieldsetViewModel
|
|
HintViewModel
|
Can be used to add a hint to the radios component.
See options for HintViewModel
|
|
ErrorMessageViewModel
|
Can be used to add an error message to the radios component.
The error message component will not display if ErrorMessage is null.
See options for ErrorMessageViewModel
|
|
FormGroupViewModel
|
Additional options for the form group containing the radios component.
See options for FormGroupViewModel
|
|
string
|
Optional prefix.
This is used to prefix the Id attribute for each
radio item input, hint and error message, separated by -.
Defaults to the Name option value.
|
|
string
|
Required.
Name attribute for all radio items.
|
|
List<RadioItemViewModel>
|
The radio items within the radios component.
See options for RadioItemViewModel
|
|
List<string>
|
Classes to add to the radios container.
|
|
Dictionary<string, string>
|
HTML attributes (for example data attributes) to add to the radios container.
|
Examples
Inline radios
@using GovUkDesignSystemDotNet
@await Html.GovUkRadios(new RadiosViewModel
{
Name = "changed-name",
Classes = ["govuk-radios--inline"],
Fieldset = new FieldsetViewModel
{
Legend = new FieldsetLegendViewModel
{
HtmlOrText = new HtmlOrText("Have you changed your name?"),
IsPageHeading = true,
Classes = ["govuk-fieldset__legend--l"]
}
},
Hint = new HintViewModel
{
HtmlOrText = new HtmlOrText("This includes changing your last name or spelling your name differently")
},
RadioItems = new List<RadioItemViewModel>
{
new RadioItemViewModel
{
Value = "yes",
Label = new LabelViewModel
{
HtmlOrText = new HtmlOrText("Yes")
}
},
new RadioItemViewModel
{
Value = "no",
Label = new LabelViewModel
{
HtmlOrText = new HtmlOrText("No")
}
},
}
})