Question

I have a list of languages, and with a combobox I can see the codes :

 @select(
            searchForm("langCode"),
    options(for (lang <- langs) yield (lang.langCode)),
            '_default -> "--- Choose a Language ---",
            '_label -> "Language"
    )

And now i want use a datalist HTML to autocomplete a text area with the codes. I have tried with this but it doesn't get the @lang.langCode value:

@inputText(searchForm("langCode"), '_label -> "Language") 
   <datalist id=langCode>
   @langs.map { lang =>
        <option>
          @lang.langCode
         </option>
    }
   </datalist>

Thank you.

Was it helpful?

Solution

Your code is mostly correct, except:

  1. Add list attribute to @inputText arguments:

    @inputText(searchForm("langCode"), '_label -> "Language", 'list -> "langCodeDatalist")

  2. Make sure id used for datalist is different from the one used for the input box:

    < datalist id="langCodeDatalist">

Once I made these changes, it worked. Check the source code to make sure @lang.langCode is getting pasted correctly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top