Bug in AppendHtml and similar

28 views
Skip to first unread message

Andreas Joseph Krogh

unread,
Jun 16, 2016, 10:52:39 AM6/16/16
to Lift
Hi all.
 
I found a bug which I think is a blocker for 3.0-final.
 
After switching to 3.0-RC3 (where the on*-event stuff is fixed for AJAX-response) we started experiencing JS-events not working. It appears it is because the returned markup from AppendHtml, where the markup contains on*-events is something like this:
 
jQuery('#' + "F397700660391T24JCX").append(((function () {
   lift.onEvent("lift-event-js-F397700660826TXLHFS", "click", function (event) {
      EmailSend.downloadFileFix(event);
   });
   lift.onEvent("lift-event-js-F397700660827VELI0U", "click", function (event) {
      lift.ajax("F397700660825QGZIET=true", null, null, null);
      return false;
   });
   return "<div id=\"F3977006608239FSFEM\" class=\"attachment\">\u000a\u0009\u0009\u0009\u0009\u0009\u0009\u0009<span><span class=\"fileIcon jpg\"></span></span>\u000a\u0009\u0009\u0009\u0009\u0009\u0009\u0009<span class=\"fileName\"><a id=\"lift-event-js-F397700660826TXLHFS\" data-lift-removed-attributes=\"onclick\" href=\"/visena/origo/no/email/attachment/1669/62/fisk2(1).JPG?F397700660824RLLG1S=_\">fisk2(1).JPG</a></span>\u000a\u0009\u0009\u0009\u0009\u0009\u0009\u0009<span class=\"type\">image/jpeg</span>\u000a\u0009\u0009\u0009\u0009\u0009\u0009\u0009<span class=\"size\">5.41 M</span>\u000a\u0009\u0009\u0009\u0009\u0009\u0009\u0009<a id=\"lift-event-js-F397700660827VELI0U\" data-lift-removed-attributes=\"onclick\" class=\"iconDelete\"><img src=\"/visena/files/web/images/icons/16/delete.png\"></a>\u000a\u0009\u0009\u0009\u0009\u0009\u0009</div>";
})()));
Here you see that the events are installed by lift.onEvent() before the markup is appended to the DOM.
 
This is because the AppendHtml is defined like this:
case class JqAppend(content: NodeSeq) extends JsExp with JsMember {
  override val toJsCmd = 
    "append("+fixHtmlFunc("inline", content){a => a}+")"      
}
object AppendHtml {
  def apply(uid: String, content: NodeSeq): JsCmd =
    JqJE.JqId(JE.Str(uid)) ~> JqJE.JqAppend(content)
}
 
 
If, however, I use a custom version OrigoAppendHtml, like the one below, it works:
 
private case class Append(content: NodeSeq) extends JsExp with JsMember {
   override val toJsCmd = fixHtmlCmdFunc("inline", content){"append(" + _ + ")"}
}

object OrigoAppendHtml {
   def apply(uid: String, content: NodeSeq): JsCmd =
      JqId(JE.Str(uid)) ~> Append(content)

   def apply(exp: JsExp, content: NodeSeq): JsCmd =
      (Jq(exp) ~> Append(content)).cmd
}
 
Is there a reason why we use fixHtmlFunc, and not fixHtmlCmdFunc? And shouldn't the call to "append" , in JqAppend.toJsCmd be "inside" fixHtmlFunc, like in my custom Append-class
 
 
I see the same applies to PrependHtml and maybe others.
 
I propose to fix this before 3.0-final, or else it is actually broken...
 
--
Andreas Joseph Krogh
CTO / Partner - Visena AS
Mobile: +47 909 56 963

Antonio Salazar Cardozo

unread,
Jun 16, 2016, 2:02:18 PM6/16/16
to Lift
Yikes! Yeah, I agree with the change you're proposing. `fixHtmlCmdFunc` is
I think generally the right thing to do anyway, but I never spent enough time
with that set of functions could use removing.
Thanks,
Antonio

Andreas Joseph Krogh

unread,
Jun 16, 2016, 2:32:43 PM6/16/16
to lif...@googlegroups.com
På torsdag 16. juni 2016 kl. 20:02:18, skrev Antonio Salazar Cardozo <savedf...@gmail.com>:
Yikes! Yeah, I agree with the change you're proposing. `fixHtmlCmdFunc` is
I think generally the right thing to do anyway, but I never spent enough time
with that set of functions could use removing.
Thanks,
Antonio
 
Ok, I'll prepare a PR for the relevant changes.

Antonio Salazar Cardozo

unread,
Jun 16, 2016, 10:57:12 PM6/16/16
to Lift
Thanks for catching this, Andreas!

Andreas Joseph Krogh

unread,
Jun 17, 2016, 3:43:54 AM6/17/16
to lif...@googlegroups.com
På fredag 17. juni 2016 kl. 04:57:11, skrev Antonio Salazar Cardozo <savedf...@gmail.com>:
Thanks for catching this, Andreas!
 

Antonio Salazar Cardozo

unread,
Jun 19, 2016, 10:26:28 AM6/19/16
to Lift
Had a quick look and left a note—I think there was in fact a reason why we
weren't using fixHtmlCmdFunc, but it brings up a bit of a hornet's nest of questions.
Thanks,
Antonio
Reply all
Reply to author
Forward
0 new messages