I want to create a <select> without using the helpers (because the select helper is generating a lot of html)
So, I get a list of cities from the Controller like:
public static List<City> getAllSortedByNameAsc() {
List<City> cities = new ArrayList<City>();
cities.addAll(City.find.orderBy("name").findList());
return cities;
}
In my template, I create the options with this code:
@cities.map { city =>
<option value="@city.id">@city.name</option>
}
which works, but I also want to have the chosen city as selected value. I tried several things like this:
@cities.map { city =>
<option value="@city.id" selected="@if(offerForm("city.id").value == city.id){selected}">@city.name</option>
}
But that doesn’t work. Can anyone give me a hint?
Configuration File: application.conf
Controller Class => Application.java
Model Class => City.java:
Template File => index.scala.html