Orchard/src/Orchard.Web/Modules/Orchard.Fields/Views/EditorTemplates/Fields/Enumeration.Edit.cshtml
Benedek Farkas 5c3d045aa1
Some checks failed
Compile / Compile .NET solution (push) Has been cancelled
Compile / Compile Client-side Assets (push) Has been cancelled
#8800: Reverting breaking changes to Enumeration Fields caused by #8789 (#8824)
* Revert "#8640: Fixing consistency between different Enumeration Field flavors' data storage (#8789)"

This reverts commit fdbb06ba8d.

* Re-adding change to fix that changing the ListMode of an EnumerationField from a multi-select to a single-select flavor shouldn't break the editor

* Code styling in Fields/Enumeration.Edit.cshtml
2025-01-23 11:59:24 +01:00

72 lines
3.0 KiB
Plaintext

@model Orchard.Fields.Fields.EnumerationField
@using Orchard.Fields.Settings;
@{
var settings = Model.PartFieldDefinition.Settings.GetModel<EnumerationFieldSettings>();
string[] options = (!String.IsNullOrWhiteSpace(settings.Options)) ?
settings.Options.Split(new string[] { System.Environment.NewLine }, StringSplitOptions.None)
: new string[] { T("Select an option").ToString() };
}
<fieldset>
<label for="@Html.FieldIdFor(m => m.Value)" @if (settings.Required) { <text> class="required" </text> }>@Model.DisplayName</label>
@switch (settings.ListMode) {
case ListMode.Dropdown:
@Html.DropDownListFor(
m => m.Value,
new SelectList(options, Model.SelectedValues.FirstOrDefault()),
settings.Required ? new { required = "required" } : null)
break;
case ListMode.Radiobutton:
foreach (var option in options) {
if (string.IsNullOrWhiteSpace(option)) {
<label>@Html.RadioButton(
"Value",
"",
string.IsNullOrWhiteSpace(Model.SelectedValues.FirstOrDefault()),
settings.Required ? new { required = "required" } : null)<i>@T("unset")</i>
</label>
}
else {
<label>@Html.RadioButton(
"Value",
option,
option == Model.SelectedValues.FirstOrDefault(),
settings.Required ? new { required = "required" } : null)@option
</label>
}
}
break;
case ListMode.Listbox:
<input name="@Html.FieldNameFor(m => m.SelectedValues)" type="hidden" />
@Html.ListBoxFor(
m => m.SelectedValues,
new MultiSelectList(options, Model.SelectedValues),
settings.Required ? new { required = "required" } : null)
break;
case ListMode.Checkbox:
int index = 0;
<input name="@Html.FieldNameFor(m => m.SelectedValues)" type="hidden" />
foreach (var option in options) {
index++;
if (!string.IsNullOrWhiteSpace(option)) {
<div>
<input type="checkbox" name="@Html.FieldNameFor(m => m.SelectedValues)" value="@option"
@((Model.SelectedValues != null && Model.SelectedValues.Contains(option)) ? "checked=\"checked\"" : "")
class="check-box" id="@Html.FieldIdFor(m => m.SelectedValues)-@index" />
<label class="forcheckbox" for="@Html.FieldIdFor(m => m.SelectedValues)-@index">@option</label>
</div>
}
}
break;
}
@Html.ValidationMessageFor(m => m.SelectedValues)
@if (HasText(settings.Hint)) {
<span class="hint">@settings.Hint</span>
}
</fieldset>