Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add Dynamic binding style

  • Loading branch information...
commit b9d5264f99321ce8e196f2e2f0425561c5de1ca3 1 parent 1a360c9
pbrant pbrant authored
13 web/webkit/src/main/scala/net/liftweb/http/CssBoundScreen.scala
View
@@ -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 = {
6 web/webkit/src/main/scala/net/liftweb/http/LiftScreen.scala
View
@@ -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)
}
Please sign in to comment.
Something went wrong with that request. Please try again.