Skip to content

Commit 21e19a3

Browse files
committed
Assign unique ids to radio buttons
In #153870f, I attempted to mitigate the issue of .NET Core assigning duplicate `id`s to radio buttons bound using the `asp-for` tag helper by using `id=""`. This didn't actually work as intended, however, as Chrome still sees `id` as a duplicate (multiple elements having a `null` `id` presumably). To mitigate this, I am using `GetFullHtmlFieldName()` and `CreateSantizedId()` to generate a unique identifier based on the existing HTML field prefix.
1 parent 5aa7bfc commit 21e19a3

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

  • OnTopic.Editor.AspNetCore/Areas/Editor/Views/Editor/Components/Boolean

OnTopic.Editor.AspNetCore/Areas/Editor/Views/Editor/Components/Boolean/Default.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
<div class="@Model.AttributeDescriptor.CssClass form-check form-check-inline">
88
<label class="form-check-label">
9-
<input type="radio" asp-for="Value" value="1" id="" class="form-check-input" checked=@Model.IsTrue() disabled=@(!Model.AttributeDescriptor.IsEnabled) required=@Model.AttributeDescriptor.IsRequired /> Yes
9+
<input type="radio" asp-for="Value" value="1" id="@TagBuilder.CreateSanitizedId(ViewData.TemplateInfo.GetFullHtmlFieldName("Yes"), "_")" class="form-check-input" checked=@Model.IsTrue() disabled=@(!Model.AttributeDescriptor.IsEnabled) required=@Model.AttributeDescriptor.IsRequired /> Yes
1010
</label>
1111
</div>
1212
<div class="form-check form-check-inline">
1313
<label class="form-check-label">
14-
<input type="radio" asp-for="Value" value="0" id="" class="form-check-input" checked=@Model.IsFalse() disabled=@(!Model.AttributeDescriptor.IsEnabled) required=@Model.AttributeDescriptor.IsRequired /> No
14+
<input type="radio" asp-for="Value" value="0" id="@TagBuilder.CreateSanitizedId(ViewData.TemplateInfo.GetFullHtmlFieldName("No"), "_")" class="form-check-input" checked=@Model.IsFalse() disabled=@(!Model.AttributeDescriptor.IsEnabled) required=@Model.AttributeDescriptor.IsRequired /> No
1515
</label>
1616
</div>

0 commit comments

Comments
 (0)