Duplicate divs in tutorial

2 views
Skip to first unread message

Adam Warski

unread,
Dec 23, 2009, 4:46:34 PM12/23/09
to Lift
Hello,

just a note to the snippets written in the tutorial. The elements of the todo list, when changed (e.g. the "done" checkbox), submit and redraw the list. The code for that is (Listing 17):

def list(html: NodeSeq) = {
val id = S.attr("all_id").open_!

def inner(): NodeSeq = {
def reDraw() = SetHtml(id, inner())

bind("todo", html,
"exclude" ->
ajaxCheckbox(QueryNotDone, v => {QueryNotDone(v); reDraw}),
"list" -> doList(reDraw) _)
}

inner()
}

And the corresponding template:

<lift:TD.list all_id="all_todos">
<div id="all_todos">
<!-- proper list -->
</div>
</lift:TD.list>

As SetHtml sets the children of the element with the specified id, after one change of the checkbox and one ajax call, there will be a <div id="all_todos"> inside the original <div id="all_todos"> (as we set the children of the original element to be the nodes passed to the snippet). So you end up with:

<lift:TD.list all_id="all_todos">
<div id="all_todos">
<div id="all_todos">
<!-- proper list -->
</div>
</div>
</lift:TD.list>

Subsequent calls don't produce any more divs, as the children of the first div with id "all_todos" get replaced. However, I think it's not too "clean" to produce markup like that.
The solution I think would be to (somehow) strip the outer div of the html NodeSeq and use that in the ajax reDraw method, instead of capturing the original html with a closure.
But probably Lift gurus have a better solution :).

--
Adam

Marius

unread,
Dec 23, 2009, 5:19:21 PM12/23/09
to Lift
Why not something like:

<div id="all_todos">
<lift:TD.list all_id="all_todos">
...
</lift:TD.list>
</div>


Br's,
Marius

Adam Warski

unread,
Dec 24, 2009, 3:25:19 AM12/24/09
to lif...@googlegroups.com
Heh, of course :)
Can you (or somebody else) fix Listing 12 in the tutorial then?

Adam

> --
>
> You received this message because you are subscribed to the Google Groups "Lift" group.
> To post to this group, send email to lif...@googlegroups.com.
> To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.
>
>

Marius

unread,
Dec 24, 2009, 6:06:37 AM12/24/09
to Lift
Personally I don't have much time for it now but could you please open
a defect here?: http://github.com/dpp/liftweb/issues

Br's,
Marius

Reply all
Reply to author
Forward
0 new messages