Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using LiftScreen field or text

Tags:

scala

lift

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.

like image 805
Filippo De Luca Avatar asked Feb 15 '11 19:02

Filippo De Luca


1 Answers

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.

like image 70
Dylan Lacey Avatar answered Sep 25 '22 02:09

Dylan Lacey