MichaSchumann MichaSchumann - 1 year ago 122
HTML Question

Play Framework 2.1.0 Scala editable select box

I am extending a customer application written in play 2.1.0. The customer wants to have editable select boxes (either select an entry or enter text) like it is possible in windows applications. Is this option available in scala play too? The forms are defined like this:

<div class="row">
<div class="span8">
<fieldset>
@inputText(
studyForm("studyName"),
'_label -> Messages("interface.studyName"),
'_help -> Messages("interface.studyName.help"),
'_error -> studyForm.globalError
)

@select(
studyForm("virus"),
options =
...


I am not used to scala and the play framework and would be grateful if someone could help me here...

Answer Source

I found the solution, it is fairly easy. Given HTML5 compatibility of todays browsers, a simple input type text can do it. In Play/Scala it can be realized this way:

<div class="row">
    <div class="span8">
        <fieldset>
           ...
            @inputText(
            studyForm("virus"),
            'list -> "viruses",
            '_label -> Messages("interface.virus"),
            '_help -> Messages("interface.virus.help"),
             '_error -> studyForm.globalError
            )
...
</fieldset>
<datalist id="viruses">
  <option value="Virus 1">
  <option value="Virus 2">
  <option value="VIrus 3">
</datalist>
...

The line 'list -> "viruses" is the key to success as it creates the attribute "list" for the input field referencing the datalist created below.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download