Skip to content

Commit 2c64a53

Browse files
authored
Merge pull request #39 from TechnologyEnhancedLearning/Develop/Fixes/TD-4180_
TD-4180 update to set focus on the first item of a radio group
2 parents 487ea6a + 2c696d7 commit 2c64a53

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

NHSUKViewComponents.Web/ViewComponents/ErrorSummaryViewComponent.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,23 @@ public IViewComponentResult Invoke(string[]? orderOfPropertyNames)
1313
.SelectMany(kvp => kvp.Value.Errors.Select(e => new ErrorSummaryListItem(kvp.Key, e.ErrorMessage)))
1414
.ToList();
1515

16+
var groupingMetadata = ViewData["GroupedFormControlMetadata"] as Dictionary<string, bool>;
17+
18+
foreach (var error in errors)
19+
{
20+
string key = error.Key;
21+
bool isGrouped = groupingMetadata != null && groupingMetadata.ContainsKey(key) && groupingMetadata[key];
22+
23+
if (isGrouped)
24+
{
25+
error.Key += "-0";
26+
}
27+
}
28+
1629
var orderedErrors = GetOrderedErrors(errors, orderOfPropertyNames ?? new string[0]);
1730

1831
var errorSummaryViewModel = new ErrorSummaryViewModel(orderedErrors);
32+
1933
return View(errorSummaryViewModel);
2034
}
2135

NHSUKViewComponents.Web/Views/Shared/Components/RadioList/Default.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
@foreach (var (radio, index) in Model.Radios.Select((r, i) => (r, i)))
5353
{
5454
counter = index;
55-
var radioId = $"{radio.Value}-{index}";
55+
var radioId = $"{Model.AspFor}-{index}";
5656
if (!string.IsNullOrWhiteSpace(Model.Class))
5757
{
5858
<div class="@Model.Class">
@@ -106,7 +106,7 @@
106106
@if (Model.OptionalRadio != null)
107107
{
108108
<div class="nhsuk-radios__divider nhsuk-u-padding-left-2">or</div>
109-
var radioId = $"{Model.OptionalRadio.Value}-{++counter}";
109+
var radioId = $"{Model.AspFor}-{++counter}";
110110
<div class="nhsuk-radios__item">
111111
<input class="nhsuk-radios__input"
112112
id="@radioId"

0 commit comments

Comments
 (0)