Skip to content

Instantly share code, notes, and snippets.

@fbettag
Created June 22, 2014 00:08
Show Gist options
  • Select an option

  • Save fbettag/1d99fa3615780b61b0b0 to your computer and use it in GitHub Desktop.

Select an option

Save fbettag/1d99fa3615780b61b0b0 to your computer and use it in GitHub Desktop.
Liftweb dynamic input field creation directly from RequestVar and SessionVar
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