I'm using play framework 2.0.4
In my java file,
return ok(views.html.name.render(Name.all(),NameForm));
In my html file,
@(name: List[Name],NameForm: Form[Name])
I want to make a dropdownlist (like using select, option tags in plain HTML)by on data from name array by using @select in @import helper._
I'm quite new to Play thus can someone show me how can I archive this?
Thank you very much.
One way to do it is by defining your options as a list, returned by a static method
Create a Java class
public class ComboboxOpts {
public static List<String> myCustomOptions(){
List<String> tmp = new ArrayList();
tmp.add("This is option 1");
tmp.add("This is option 2");
tmp.add("This is option 3");
return tmp;
}
....
}
In your HTML, import the helper
@import helper._
and try
@select(
myForm("myDropdownId"),
options = options(ComboboxOpts.myCustomOptions),
'_label -> "This is my dropdown label",
'_showConstraints -> false
)
Another way to do it is to define a custom form field. See this link
@helper.form(action = routes.Application.submit(), 'id -> "myForm") {
<select>
<option>This is option 1</option>
<option>This is option 2</option>
<option>This is option 3</option>
</select>
}
Please be sure to do an extensive Google search before you ask these questions. I am sure there are tutorials and or the same question that has been already been asked
Cheers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With