简体   繁体   中英

Play Framework how to set selected option in the form?

I need to set selected option for select element, rendered with Play Framework helper. I could not find an example how to do it, even after looking at the docs .

I tried to do it like this, but still default value is selected:

@select(
    field = form("selectedCategory"),
    options = categoriesSeq,
    '_default -> "Choose One",
    '_label -> "Select category",
    'selected -> "1"
)

How to achieve it?

You may want to look at how use play forms .

In your code, what is the variable form ?

It should be a play.api.data.Form instance, passed into your view, from your controller.

I hope this helps.

Rhys

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM