[Lift] Ajaxform in a ModalDialog

53 views
Skip to first unread message

Channing Walton

unread,
Apr 30, 2010, 3:57:29 PM4/30/10
to Lift
I am struggling again with an ajaxform in a modaldialog. Are there any
examples of such a thing? I've searched but cannot find any.

Channing

--
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.

Ross Mellgren

unread,
Apr 30, 2010, 3:58:37 PM4/30/10
to lif...@googlegroups.com
I don't know of any, but what are the problems you're having? I'm sure with our powers combined, we can help you out.

-Ross

Marius

unread,
Apr 30, 2010, 4:13:43 PM4/30/10
to Lift
Channing help Captain Planet help you !

On Apr 30, 10:58 pm, Ross Mellgren <dri...@gmail.com> wrote:
> I don't know of any, but what are the problems you're having? I'm sure with our powers combined, we can help you out.
>
> -Ross
>
> On Apr 30, 2010, at 3:57 PM, Channing Walton wrote:
>
> > I am struggling again with an ajaxform in a modaldialog. Are there any
> > examples of such a thing? I've searched but cannot find any.
>
> > Channing
>
> > --
> > 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 athttp://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 lif...@googlegroups.com.
> To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/liftweb?hl=en.

Channing Walton

unread,
Apr 30, 2010, 4:37:38 PM4/30/10
to Lift
ok, I have a button on a page so that the user can create a 'note'

MySnippet:
private def addNoteForm(deal:Deal) = {

SHtml.ajaxButton("New Note",
() => S.runTemplate("templates-hidden" ::
"note_create" :: Nil).
map(ns => ModalDialog(ns)) openOr
Alert("Couldn't find note_create template"))
}

The note_create template looks like this:

<lift:snippet type="MySnippet:createNote" form="post">
<p>
Subject: <note:subject/>
</p>
....
<note:submit/>
</lift:snippet>

and the createNote method:

def createNote(xhtml:NodeSeq):NodeSeq = {
val note = new Note...

def saveNote = note.validate match {
case Nil => println("saving");note.save; initialiseNotes(deal)
case x => SetHtml("errors", x.map((e:FieldError) => <li>{e.msg}</
li>))
}
bind("note", xhtml,
"subject" -> text("", (s) =>
{println(s);note.subject(s)}),
"message" -> text("", note.message(_)),
"submit" -> submit("Save", () => saveNote & Unblock)
)
}

When the form is submitted, the correct note is created but after the
dialog is closed I get a page of javascript.

If I use an ajaxSubmit("Save", ()=>... the dialog closes but the
saveNote function is called before the functions to update the
'subject' and 'message' fields, so my note is empty.

Randinn

unread,
Apr 30, 2010, 4:41:15 PM4/30/10
to Lift
Go planet!

Ross Mellgren

unread,
Apr 30, 2010, 4:58:14 PM4/30/10
to lif...@googlegroups.com
I think you want to use ajaxForm instead, though I haven't used it very much so other people may have commentary.

That would be something like:

> The note_create template looks like this:
>

<lift snippet type="MySnippet:createNote">

> <p>
> Subject: <note:subject/>
> </p>
> ....
> <note:submit/>
> </lift:snippet>
>
> and the createNote method:
>
> def createNote(xhtml:NodeSeq):NodeSeq = {
> val note = new Note...
>
> def saveNote = note.validate match {
> case Nil => println("saving");note.save; initialiseNotes(deal)
> case x => SetHtml("errors", x.map((e:FieldError) => <li>{e.msg}</
> li>))
> }

SHtml.ajaxForm {

> bind("note", xhtml,
> "subject" -> text("", (s) =>
> {println(s);note.subject(s)}),
> "message" -> text("", note.message(_)),
> "submit" -> submit("Save", () => saveNote & Unblock)
> )

}

> }

Let me know if that helps,

-Ross

Channing Walton

unread,
Apr 30, 2010, 5:43:00 PM4/30/10
to Lift
The submit blocked unless I changed to using ajaxSubmit, but then the
save is called before the form elements update the object :)

Marius

unread,
May 1, 2010, 3:24:03 AM5/1/10
to Lift
Channing can you please provide a minimalistic Lift app that I can
just run and see the behavior you're seeing?... In Ajax forms it is
recommendable to use ajaxSubmit instead of submit and that's because
for normal submit in ajax forms the button's information is not
propagated to the server - if I recall correctly this is an JQuery
behavior stuff of serializing the forms.

The function provided in the ajaxSubmit should be called last as the
order of evaluation.

Another option is to use SHtml.submitAjaxForm(formId, func) .. you can
use this to submit forms from outside <form> say when clicking various
links/buttons etc. But let's see first your example ...


Br's,
Marius

Channing Walton

unread,
May 1, 2010, 2:41:45 PM5/1/10
to Lift
will do asap

Channing Walton

unread,
May 1, 2010, 6:04:49 PM5/1/10
to Lift
I think I have found a problem with my project.

I created a standalone example which worked as expected, but copying
the files into my existing project gave me the problem I've described
above with the save being called first.

My project is using sbt and lift 2.0M4, the experimental one used
maven and lift 2.0m4.

I guess I have another issue...!

Ross Mellgren

unread,
May 1, 2010, 6:11:27 PM5/1/10
to lif...@googlegroups.com
Is the full app private?

-Ross

Channing Walton

unread,
May 1, 2010, 6:39:22 PM5/1/10
to Lift
I have a sample app but I've actually just figured out the issue.

In the sbt project I had set System.setProperty("run.mode", "test")
for some reason. If I remove that line then the app behaves as
required. I hadn't set that property when I was running under maven so
I didn't see the issue.

Whats the preferred way to make the sample app available for people to
scrutinise?

Channing

Ross Mellgren

unread,
May 1, 2010, 6:40:47 PM5/1/10
to lif...@googlegroups.com
github works very well for posting sample apps and such.

-Ross

Marius

unread,
May 2, 2010, 4:27:39 AM5/2/10
to Lift
That's because in test mode the form function names are generated by a
different algorithm ... and it remains invariant across page changes.
Still these function names start with 'f'. However normal function
names start with 'F' an ajaxSubmit function names start with Z to
ensure evaluation of ajaxFunc at the end. But lexicographically when
you are in test mode because function names starting with 'f' are
evaluated AFTER the ajaxSubmit as it starts with 'Z'.

I just opened ticket
https://www.assembla.com/spaces/liftweb/tickets/505-function-evaluation-order-in-test-model-when-using-ajaxsubmit

Thanks for finding this ;)

Br's,
Marius

Channing Walton

unread,
May 2, 2010, 7:36:07 AM5/2/10
to Lift
Cool, do you still want an example? (Sounds like you've found the
problem.)

On May 2, 9:27 am, Marius <marius.dan...@gmail.com> wrote:
> That's because in test mode the form function names are generated by a
> different algorithm ... and it remains invariant across page changes.
> Still these function names start with 'f'. However normal function
> names start with 'F' an ajaxSubmit function names start with Z to
> ensure evaluation of ajaxFunc at the end. But lexicographically when
> you are in test mode because function names starting with 'f' are
> evaluated AFTER the ajaxSubmit as it starts with 'Z'.
>
> I just opened tickethttps://www.assembla.com/spaces/liftweb/tickets/505-function-evaluati...

Marius

unread,
May 2, 2010, 12:02:03 PM5/2/10
to Lift
No need for the example. I just pushed the fix in master. Please check
it out and let me know if it works.

Channing Walton

unread,
May 3, 2010, 9:07:45 AM5/3/10
to Lift
brilliant, thank you. I'll check it out tonight.
Reply all
Reply to author
Forward
0 new messages