Search code examples
scalatemplatesselectplayframeworkoptgroup

Playframework scala helper for select input with optgroup


Is in playframework scala helper to achive optgroup in input select?

Example:

 http://jsfiddle.net/g4ffzvs8/

Code:

<select style="width:300px" id="source">
               <optgroup label="Alaskan/Hawaiian Time Zone">
                   <option value="AK">Alaska</option>
                   <option value="HI">Hawaii</option>
               </optgroup>
               <optgroup label="Pacific Time Zone">
                   <option value="CA">California</option>
                   <option value="NV">Nevada</option>
                   <option value="OR">Oregon</option>
                   <option value="WA">Washington</option>
               </optgroup>
              </select>

Solution

  • Here is my working solution:

    <div class="clearfix @if(MedicalIncidentForm("incidentType.id").hasErrors) {error}">
        <label class="note note-title  note-@if(MedicalIncidentForm("incidentType.id").hasErrors) {error} else {success}" for="incidentType_id">Rodzaj</label>
        <div class="input note note-footer note-@if(MedicalIncidentForm("incidentType.id").hasErrors) {error} else {success}">
            <select name="incidentType.id" onchange="checkSelectedValue(this)">
                <option></option>
                @for(opt <- new IncidentType().getOptionGroups()) {
                   <optgroup label="@opt._1">
                        @for(op <- opt._2) {
                            @**
                            <option  value="@op._1">@op._2</option>
                            **@
                            <option value="@op._1" @if(MedicalIncidentForm("incidentType.id").value() == op._1) {selected="selected"}>@op._2</option>
                        }
                    </optgroup>
                }
            </select>
            </div>
    </div>