Created
June 22, 2014 00:08
-
-
Save fbettag/1d99fa3615780b61b0b0 to your computer and use it in GitHub Desktop.
Liftweb dynamic input field creation directly from RequestVar and SessionVar
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
| object SessionSettings { | |
| object requestVar = net.liftweb.http.RequestVar[String]("") | |
| object sessionVar = net.liftweb.http.SessionVar[String]("") | |
| private def ajaxText[T <: AnyVar[String, _]](id: String, placeholder: String, field: T, validate: String => Boolean) = { | |
| def customSet(str: String): JsCmd = { | |
| if (validate(str)) { | |
| field.set(str) | |
| Noop | |
| } else { | |
| // do validation alert on input id | |
| Noop | |
| } | |
| } | |
| SHtml.ajaxText(field.get, customSet(_), "id" -> id, "placeholder" -> placeholder) | |
| } | |
| def render = "#sessionVar" #> ajaxText("sessvar", "this is per session, must be more than 5 chars", sessionVar, _.trim.length > 5) & | |
| "#requestVar" #> ajaxText("reqvar", "this is per request, must be less than 5 chars", requestVar, _.trim.length < 5) & | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment