Skip to content

Instantly share code, notes, and snippets.

@Timshel
Last active December 19, 2015 21:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Timshel/6019293 to your computer and use it in GitHub Desktop.
Save Timshel/6019293 to your computer and use it in GitHub Desktop.
Multiple select example using play2 master
package controllers
import play.api._
import play.api.data._
import play.api.data.Forms._
import play.api.mvc._
object Application extends Controller {
val form = Form(
"select" -> Forms.list(nonEmptyText)
)
def index = Action {
Ok(views.html.index(form))
}
def update = Action { implicit request =>
form.bindFromRequest.fold(
formWithErrors => BadRequest(views.html.index(formWithErrors)),
values => {
play.Logger.debug( values.toString )
Ok(views.html.index(form.fill(values)))
}
)
}
}
@( form: Form[_] )
@main("Welcome to Play 2.1") {
Hello :
@helper.form( routes.Application.update ){
@helper.select(form("select"), Seq( ("1", "First value"), ("2", "Seconds value"), ("3", "Third value") ), 'multiple -> None )
<input type="submit">
}
}
# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~
# Home page
GET / controllers.Application.index
POST /update controllers.Application.update
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.at(path="/public", file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment