-
-
Save Timshel/6049540 to your computer and use it in GitHub Desktop.
#multiple #select example using play2 master
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) | |
} | |
) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@( 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"> | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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