mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 17:08:47 +08:00
No term selection option in TaxonomyField (#8667)
* Added no term selection option when taxonomy field is not required and is set to be shown as a radio button set (single choice without autocomplete) * Correctly checked the "no selection" option when SingleTermId == 0.
This commit is contained in:
parent
10e5078956
commit
55ec9e2335
@ -11,6 +11,8 @@
|
||||
|
||||
int termIndex = 0;
|
||||
var settings = Model.Settings;
|
||||
|
||||
var noSelectionId = Guid.NewGuid();
|
||||
}
|
||||
|
||||
<fieldset class="taxonomy-wrapper" data-name-prefix="@Html.FieldNameFor(m => m)" data-id-prefix="@Html.FieldIdFor(m => m)">
|
||||
@ -21,26 +23,31 @@
|
||||
<span class="hint">@Model.Settings.Hint</span>
|
||||
}
|
||||
|
||||
<ul class="terms">
|
||||
@foreach (var entry in Model.Terms) {
|
||||
var ti = termIndex;
|
||||
<li>
|
||||
@* Tabs for levels *@ @for (var i = 1; i <= entry.GetLevels(); i++) { <span class="gap"> </span> }
|
||||
@{
|
||||
var disabled = !entry.Selectable || (Model.Settings.LeavesOnly && Model.Terms.Any(t => t.Path.Contains(entry.Path + entry.Id)));
|
||||
if (Model.Settings.SingleChoice) {
|
||||
<input @if (disabled) { <text> disabled="disabled" </text> } type="radio" value="@Model.Terms[ti].Id" @if (entry.Id == Model.SingleTermId) { <text> checked="checked" </text> } name="@Html.FieldNameFor(m => m.SingleTermId)" id="@Html.FieldIdFor(m => m.Terms[ti].IsChecked)" data-term="@entry.Name.ToLower()" />
|
||||
}
|
||||
else {
|
||||
<input @if (disabled) { <text> disabled="disabled" </text> } type="checkbox" value="true" @if (entry.IsChecked) { <text> checked="checked" </text> } name="@Html.FieldNameFor(m => m.Terms[ti].IsChecked)" id="@Html.FieldIdFor(m => m.Terms[ti].IsChecked)" data-term="@entry.Name.ToLower()" />
|
||||
}
|
||||
<ul class="terms">
|
||||
@if (Model.Settings.SingleChoice && !settings.Required) {
|
||||
<li>
|
||||
<input type="radio" value="0" @if (Model.SingleTermId == 0) { <text> checked="checked" </text> } name="@Html.FieldNameFor(m => m.SingleTermId)" id="@noSelectionId" data-term="@T("No selection")" />
|
||||
<label class="forcheckbox" for="@noSelectionId">@T("No selection")</label>
|
||||
</li>
|
||||
}
|
||||
@foreach (var entry in Model.Terms) {
|
||||
var ti = termIndex;
|
||||
<li>
|
||||
@* Tabs for levels *@ @for (var i = 1; i <= entry.GetLevels(); i++) {<span class="gap"> </span>}
|
||||
@{
|
||||
var disabled = !entry.Selectable || (Model.Settings.LeavesOnly && Model.Terms.Any(t => t.Path.Contains(entry.Path + entry.Id)));
|
||||
if (Model.Settings.SingleChoice) {
|
||||
<input @if (disabled) { <text> disabled="disabled" </text> } type="radio" value="@Model.Terms[ti].Id" @if (entry.Id == Model.SingleTermId) { <text> checked="checked" </text> } name="@Html.FieldNameFor(m => m.SingleTermId)" id="@Html.FieldIdFor(m => m.Terms[ti].IsChecked)" data-term="@entry.Name.ToLower()" />
|
||||
} else {
|
||||
<input @if (disabled) { <text> disabled="disabled" </text> } type="checkbox" value="true" @if (entry.IsChecked) { <text> checked="checked" </text> } name="@Html.FieldNameFor(m => m.Terms[ti].IsChecked)" id="@Html.FieldIdFor(m => m.Terms[ti].IsChecked)" data-term="@entry.Name.ToLower()" />
|
||||
}
|
||||
@Html.HiddenFor(m => m.Terms[ti].Id)
|
||||
<label class="forcheckbox" for="@Html.FieldIdFor(m => m.Terms[ti].IsChecked)">@entry.Name</label>
|
||||
</li>
|
||||
termIndex++;
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
@Html.HiddenFor(m => m.Terms[ti].Id)
|
||||
<label class="forcheckbox" for="@Html.FieldIdFor(m => m.Terms[ti].IsChecked)">@entry.Name</label>
|
||||
</li>
|
||||
termIndex++;
|
||||
}
|
||||
</ul>
|
||||
|
||||
@if (Model.TaxonomyId == 0) {
|
||||
<p>@T("You haven't specified a taxonomy for {0}", Model.DisplayName)</p>
|
||||
|
Loading…
Reference in New Issue
Block a user