I'm using the LiftScreen
trait and I have a doubt about the field and text methods. The text method use the makeField
method and then the SHtml.text
to render the field, while field
method use a FormVendor
trait to render the html.
So which is the best way to add a field? I had to use the field method or the text/password/etc methods?
Thank you.
The field method is a bit of syntactic sugar to create fields using field generators. It uses default values from that generator to create the field.
The makeField method allow for exact specifications of your field.
As such, there is no "One best answer". If you are happy with the default fields created by the FormVendor, use them. If you need more particular control over your fields, use makeField.
makeField effectively takes the arguments given to it, and uses them to create a custom field. For example,makeField("Password", "", SHtml.password(is, set _))
is effectively equal to
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 _)
}
}
(Taken from Adding Custom Field Types to LiftScreen)
This only applies to one LiftScreen. If you need to use a custom field on multiple LiftScreen's, create a stand-along trait, the Lift Wiki states "You can set up global Type → Form vendors in LiftRules.vendForm for application-scope form vending". This page in particular has some example code and more explanation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With