Using LiftScreen field or text

被刻印的时光 ゝ 提交于 2019-12-06 03:58:28

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/5008793/using-liftscreen-field-or-text

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!