Browse files

Add Dynamic binding style

  • Loading branch information...
1 parent 1a360c9 commit b9d5264f99321ce8e196f2e2f0425561c5de1ca3 @pbrant pbrant committed Jun 12, 2012
View
13 web/webkit/src/main/scala/net/liftweb/http/CssBoundScreen.scala
@@ -163,9 +163,20 @@ trait CssBoundScreen extends ScreenWizardRendered with Loggable {
} yield traceInline("Binding custom field %s to %s".format(bindingInfo.selector(formName), custom.template),
bindingInfo.selector(formName) #> bindField(field)(custom.template))
+ def dynamicFields: List[CssBindFunc] =
+ for {
+ field <- fields
+ bindingInfo <- field.binding
+ dynamic <- Some(bindingInfo.bindingStyle) collect { case d:Dynamic => d }
+ } yield {
+ val template = dynamic.func()
+ traceInline("Binding dynamic field %s to %s".format(bindingInfo.selector(formName), template),
+ bindingInfo.selector(formName) #> bindField(field)(template))
+ }
+
def bindFields: CssBindFunc = {
logger.trace("Binding fields", fields)
- List(templateFields, selfFields, defaultFields, customFields).flatten.reduceLeft(_ & _)
+ List(templateFields, selfFields, defaultFields, customFields, dynamicFields).flatten.reduceLeft(_ & _)
}
def bindField(f: ScreenFieldInfo): NodeSeq => NodeSeq = {
View
6 web/webkit/src/main/scala/net/liftweb/http/LiftScreen.scala
@@ -1672,5 +1672,11 @@ object FieldBinding {
*/
case class Custom(template: NodeSeq) extends BindingStyle
+ /**
+ * Bind the field using the results of a function. The provided function will be called
+ * every time the field is rendered.
+ */
+ case class Dynamic(func: () => NodeSeq) extends BindingStyle
+
def apply(fieldName: String) = new FieldBinding(fieldName, Default)
}

0 comments on commit b9d5264

Please sign in to comment.