Taxonomy List As A Dropdown Form Field

Topics: Customizing Orchard
Nov 6, 2012 at 5:54 PM

I have a number of taxonomy list, which I'll need to use as form fields on a form page.  I used Custom Forms to create this page.  However, the list shows up as radio buttons.  What's the best approach to turn this into a drop-down list? 

Nov 6, 2012 at 11:06 PM

There are ways to override a template from another module, but in this case, I think this should be supported by the Taxonomies module. There should be a setting to choose between radios and drop-down. So either build it and send a pull request, or ask Sébastien pretty pretty please ;)

Mar 23, 2013 at 10:43 PM
FYI @WestsideWebGal,

I believe the code in the Contrib.Taxonomies module that renders the inputs is contained in ~\Views\EditorTemplates\Fields\Contrib.TaxonomyField.cshtml:
    <div class="expando">
        @if (!String.IsNullOrWhiteSpace(Model.Settings.Hint)) {
        <span class="hint">@Model.Settings.Hint</span>
            @foreach (var entry in Model.Terms) {
                ti = termIndex;
                @* Tabs for levels *@ @for ( var i = 1; i <= entry.GetLevels(); i++ ) { <span class="gap">&nbsp;</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)"/> 
                    } 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)"/> 
                @Html.HiddenFor(m => m.Terms[ti].Id)
                <label class="forcheckbox" for="@Html.FieldIdFor(m => m.Terms[ti].IsChecked)">@entry.Name</label>