scalaplayframeworkscala-template

How to prefill a dropdown using scala template and play framework


I am using scala template and Play 2.0 framework for my project. Let's say I have a user form with fields like name (textfield), age (dropdown). While creating the user I filled name as dave and selected age as 25.

Now on my edit screen, I want my values to be prefilled, i know how to do it with textfield (i.e. set value as userForm('name')) but what about the dropdown? how to do it.


Solution

  • Thanks Shawn Downs and biesior.

    Well, we can use @select scala helper class to show the pre-filled result. like.

     @select(userForm("age"),models.Age.values().toList.map(v => (v.getDisplayName(), v.getDisplayName())),'id->"age")
    

    To show other options I have used an enum of possible values of age.