Aliasgar Rajpiplawala
Aliasgar Rajpiplawala

Reputation: 656

Create a Dropdownlist with option group using custom forms in Orchard

I need to create a select box with option group in Orchard. I am using Enumeration field to generate the dropdown but i really dont know how can I add OptGroup in the dropdown. Please can someone help me on this as I am not able to find much.

Upvotes: 1

Views: 817

Answers (1)

Jerome2606
Jerome2606

Reputation: 955

You should consider to override the Enumeration.cshtml shape with your own.

In this file, the header contains the logical of presentation of the selected values:

@using Orchard.Utility.Extensions;
@using System.Linq;
@{
string valueToDisplay = string.Empty;
string[] selectedValues = Model.ContentField.SelectedValues;
if (selectedValues != null) {
    string valueFormat = T("{0}").ToString();
    string[] translatedValues = selectedValues.Select(v => string.Format(valueFormat, T(v).Text)).ToArray();
    string separator = T(", ").ToString();
    valueToDisplay = string.Join(separator, translatedValues);
}
if (!string.IsNullOrEmpty(valueToDisplay)) {
    string name = Model.ContentField.DisplayName;
<p class="enumeration-field [email protected]()">
    <span class="name">@name:</span>
    <span class="value">@Html.Raw(valueToDisplay)</span>
</p>

}
}

You can write your options like:

val1,optGroup;val2,optGroup;val3,optGroup2 ...

Upvotes: 1

Related Questions