Skip to content

Commit af5e765

Browse files
committed
Ensured that optional topic list doesn't break editor
In a recent update (753d0a4), the `TopicListViewComponent` was updated to not render to the interface if there were no items to render in the list—or, rather, if the only item was the default placeholder label with an empty value. In those cases, it doesn't make sense to cluter the interface with an empty dropdown menu. Unfortunately, this broke OnTopic. Because this was being removed as part of a loop over ` GetAttributeDescriptors()`, it introduced a gap in the naming convention used for the `name` attribute (e.g., `Attributes[0]`, `Attributes[2]`…). And the default model binding in MVC will stop looking for subsequent fields in a collection if it encounters a gap. As such, any attributes placed after an empty `TopicListViewComponent` also wouldn't be displayed. Oops! This fixed that by rendering the necessary fields as `<hidden />` inputs, thus allowing the attribute to be hidden from the interface, while still providing ASP.NET Core the information it needs to maintain correct model binding. In this case, the `TopicListViewComponent` will still get `POST`ed to the server, but as whatever its existing value is, which is what we want. That way, it won't get overwritten if, for some reason, it's set to a value.
1 parent acecc86 commit af5e765

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

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

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,9 @@
1515
required =@Model.AttributeDescriptor.IsRequired
1616
>
1717
</select>
18+
}
19+
else {
20+
<input type="hidden" asp-for="AttributeDescriptor.Key" />
21+
<input type="hidden" asp-for="AttributeDescriptor.ContentType" />
22+
<input type="hidden" asp-for="Value" />
1823
}

0 commit comments

Comments
 (0)