Version 5, last updated by Diego Medina at August 09, 2011 22:00 UTC
Add custom field types to LiftScreen
Here’s a small snippet showing you how to add custom field types to a single LiftScreen:
object MyScreen extends LiftScreen {
val password = new Field {
type ValueType = String
override def name = "Password"
override implicit def manifest = buildIt[String]
override def default = ""
override def toForm: Box[NodeSeq] = SHtml.password(is, set _)
}
}
If you need to use something in multiple LiftScreens, you can register a global form builder.
Now, if you want a password field, there is a password method in LiftScreen, you can use it like this:
val pass= password("My Password field", "")
Pretty easy :)
There are several other helper methods worth looking at, just check
framework/web/webkit/src/main/scala/net/liftweb/http/LiftScreen.scala
Using editable_?
If you would like to use editable_? the abode example needs a little change, you need to change
override implicit def manifest = buildIt[String]
for
lazy val manifest = buildIt[ValueType]
Complete example is:
val name = new Field {
type ValueType = String
override def name = "Name"
override def default = "Diego"
lazy val manifest = buildIt[ValueType]
override def editable_? = false
}
Otherwise you get a stackoverflow referring to the line
override implicit def manifest = buildIt[String]