Skip to content

Commit 1e81eb0

Browse files
committed
Mitigated issue with non-nullable checkboxes
The `ImportOptions.DeleteUnmatched*` attributes are all `bool`, but are backed by a nullable `bool?` which defaults to `null` and inherits its value based on the `ImportOptions.Strategy` value. Unfortunately, when using the ASP.NET Core `input` tag helper with checkboxes, a hidden field is generated with the value of `false`. This results in the value of these properties _always_ being set to false, and no longer determing their value from the `ImportOptions.Strategy`. We only want that to happen when they're set to `true`. To mitigate that, we're removing the tag helper, and manually defining the `name` attribute. This introduces a risk in the case that the `enum` values change; to help avoid that potentiality in the future, we used `nameof()` on both the `enum` as well as its fields, so a compilation error will occur if those values are altered.
1 parent 3eb0a30 commit 1e81eb0

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

OnTopic.Editor.AspNetCore/Areas/Editor/Views/Editor/Import.cshtml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,22 +147,22 @@
147147
<h3>Delete Unmatched…?</h3>
148148
<section class="attribute">
149149
<label>
150-
<input type="checkbox" asp-for="ImportOptions.DeleteUnmatchedAttributes" /> Attributes
150+
<input type="checkbox" name="@nameof(ImportOptions).@nameof(ImportOptions.DeleteUnmatchedAttributes)" value="true" /> Attributes
151151
<i class="fa fa-info-circle" data-toggle="tooltip" data-placement="right" title="Deletes existing attributes if they aren't included in the import. Implicit if the merge strategy is set to replace."></i>
152152
</label>
153153
<br />
154154
<label>
155-
<input type="checkbox" asp-for="ImportOptions.DeleteUnmatchedRelationships" /> Relationships
155+
<input type="checkbox" name="@nameof(ImportOptions).@nameof(ImportOptions.DeleteUnmatchedRelationships)" value="true" /> Relationships
156156
<i class="fa fa-info-circle" data-toggle="tooltip" data-placement="right" title="Deletes existing relationships if they aren't included in the import. Implicit if the merge strategy is set to replace."></i>
157157
</label>
158158
<br />
159159
<label>
160-
<input type="checkbox" asp-for="ImportOptions.DeleteUnmatchedNestedTopics" /> Nested Topics
160+
<input type="checkbox" name="@nameof(ImportOptions).@nameof(ImportOptions.DeleteUnmatchedNestedTopics)" value="true" /> Nested Topics
161161
<i class="fa fa-info-circle" data-toggle="tooltip" data-placement="right" title="Deletes existing nested topics if they aren't included in the import. Implicit if the merge strategy is set to replace."></i>
162162
</label>
163163
<br />
164164
<label>
165-
<input type="checkbox" asp-for="ImportOptions.DeleteUnmatchedChildren" /> Children
165+
<input type="checkbox" name="@nameof(ImportOptions).@nameof(ImportOptions.DeleteUnmatchedChildren)" value="true" /> Children
166166
<i class="fa fa-info-circle" data-toggle="tooltip" data-placement="right" title="Deletes existing children—including nested topics—if they aren't included in the import. Implicit if the merge strategy is set to replace."></i>
167167
</label>
168168
</section>

0 commit comments

Comments
 (0)