Hello,

> With SetHtml you just provide the parent element ID and the NodeSeq
> you want to render as a child of that parent. You're saying you don;t
> have the NodeSeq Corresponding to the List but I assume you do have
> the list right? So assume this Ajax function:
> 
> def myCallback(): JsCmd = {
> val myList = ...
> 
> val html: NodeSeq = myList.flatMap(e => <td>{e toString}</td>)
> 
> SetHtml("all_todos", html)
> 
> }
But then I'm embedding view logic into the code - I wouldn't really want to do 
that. Especially once the list becomes anything more fancy then a simple table, 
I think putting the list-displaying into an html file better.

I tried doing something else, expanding your idea.
I've put the list-displaying html markup into a template (todo_list.html), so 
now I can reuse it to both display the list and pass it to the snippet which 
handles and binds the form:

Now my form looks like this:

<lift:TD.add form="post">
<addForm:form>
  <!-- fields and submit button bound here -->
</addForm:form>
<addForm:list>
  <lift:embed what="todo_list" />
</addForm:list>
</lift:TD.add>

<!-- some other code -->

<!-- the list that I want to redraw -->
<lift:embed what="todo_list" />

In TD.add I have then:
...
def drawList() = list(chooseTemplate("addForm", "list", form))
def reDraw() = SetHtml("all_todos", drawList())

bind("todo", chooseTemplate("addForm", "form", form),
"priority" -> todo.priority.toForm,
"desc" -> todo.desc.toForm,
"submit" -> submit("New", checkAndSave))
)
...

Is this the right way to go? And is it the "lift" way?

Anyway I can't test it yet because I can't get my form to be submitted with 
ajax. Both surrounding the bind with SHtml.ajaxForm(...) and replacing submit 
with ajaxButton causes the form to stop working (the values in the model aren't 
updated).

Adam

> Br's,
> Marius
> 
> On Dec 23, 10:32 am, Adam Warski <[email protected]> wrote:
>> Hello,
>> 
>> I'm just starting with Lift, and there's one thing I can't figure out. I 
>> want to modify the ToDo example from the tutorial so that the "Add" button 
>> makes an ajax call, adds the element to a list and displays the modified 
>> result.
>> 
>> The problem is that I don't know how to redraw the list after the button has 
>> been pressed. More generally: how to redraw a page fragment with ajax? I 
>> could do that with SetHtml if I had the NodeSeq corresponding to the list, 
>> but the button is in an "unrelated" page fragment so it doesn't have it. 
>> What's the Lift way to solve such problems?
>> 
>> The page roughly is:
>> 
>> <lift:TD.add form="post">
>> <!-- fields an submit button bound here -->
>> </lift:TD.add>
>> 
>> <!-- some other code -->
>> 
>> <!-- the list that I want to redraw -->
>> <lift:TD.list all_id="all_todos">
>> ...
>> </lift:TD.list>
>> 
>> I was looking through the list archive but didn't find anything. Sorry if 
>> it's a repeated question :)
>> 
>> --
>> Adam
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Lift" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/liftweb?hl=en.
> 
> 

--

You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en.


Reply via email to