Skip to content

Commit d12e3d4

Browse files
committed
Merge branch 'bugfix/Optional-TopicList' into develop
When a `TopicListViewComponent` is bound to a topic containing no children, it is removed from the interface, since there's no point in displaying an empty dropdown box. Because of how ASP.NET Core handles data binding of collections, however, this caused all subsequent attributes not to be properly bound in the editor. In the best case scenario, this threw an exception. In the worst case scenario, it would delete the values of all subsequent attributes. (In most cases, it likely threw a required field validation error.) To mitigate this, this bug fix emits hidden attributes to satisfy the expectations of ASP.NET Core data binding, while maintaining whatever the existing value for the attribute would have been. This allows us to continue to remove empty dropdown boxes from the interface, while also addressing this bug.
2 parents acecc86 + 0b9015a commit d12e3d4

1 file changed

Lines changed: 10 additions & 6 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: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@
88

99
@if (Model.TopicList.Count > 1) {
1010
<select
11-
asp-for ="Value"
12-
asp-items ="Model.TopicList"
13-
class ="@Model.AttributeDescriptor.CssClass form-control form-inline"
14-
disabled =@(!Model.AttributeDescriptor.IsEnabled)
15-
required =@Model.AttributeDescriptor.IsRequired
16-
>
11+
asp-for ="Value"
12+
asp-items ="Model.TopicList"
13+
class ="@Model.AttributeDescriptor.CssClass form-control form-inline"
14+
disabled =@(!Model.AttributeDescriptor.IsEnabled)
15+
required =@Model.AttributeDescriptor.IsRequired>
1716
</select>
17+
}
18+
else {
19+
<input type="hidden" asp-for="AttributeDescriptor.Key" />
20+
<input type="hidden" asp-for="AttributeDescriptor.ContentType" />
21+
<input type="hidden" asp-for="Value" />
1822
}

0 commit comments

Comments
 (0)