Re: [Lift] Re: Ajax button + submitting a form

2010-01-13 Thread Adam Warski
Also, interestingly, if you change the order of binding from: bind("cont", containerTemplate, "name" -> { println("bind container name " + cont.name); SHtml.text(cont.name, (s: String) => {println("set container name " + s); cont.name = s; }) }, "rooms" -> editRoom _,

Re: [Lift] Re: Ajax button + submitting a form

2010-01-13 Thread Adam Warski
Hello, > Yes please a small app would be best. Please use 2.0-SNAPSHOT. Here it is: http://github.com/adamw/lift-ajax-submit-test/ Steps to reproduce: 1. checkout from git :) 2. run mvn jetty:run 3. go to http://localhost:8080 4. click "add" once 5. fill in the two fields with some values e.g. "

Re: [Lift] Re: Ajax button + submitting a form

2010-01-13 Thread Adam Warski
Hello, the problem is that some form elements are updated, then the function is called, and then the rest of the form elements are updated. My code is more or less something like this: def editElement(elementTemplate: NodeSeq): NodeSeq = { container.elements.flatMap { element: Element

Re: [Lift] Re: Ajax button + submitting a form

2010-01-12 Thread Adam Warski
Hello, this *almost* works :). I modified your code a bit and now I have: def ajaxButton(text: NodeSeq, formId: String, func: () => JsCmd, attrs: (String, String)*): Elem = { attrs.foldLeft(fmapFunc(contextFuncBuilder(func))(name => {text}))(_ % _) } Now the form submits and

Re: [Lift] Re: Ajax button + submitting a form

2010-01-11 Thread Adam Warski
Hello, trying the solution a bit more I came into another problem which I can't solve elegantly. The solution below works nicely for an "add" button, but a "delete" button causes more problems: the problem is that with "delete", you must know which element should get deleted. In a no-ajax sol

Re: [Lift] Re: Ajax button + submitting a form

2010-01-11 Thread Adam Warski
Hello, > I don't think you need a SessionVar. You can just capture the RequestVar's > value in a local val and refer to that in the closure. > Basically if I understand correctly, this is a typical scenario where you > output a form and associate functions with its fields which are to be > exec

Re: [Lift] Re: Ajax button + submitting a form

2010-01-11 Thread Adam Warski
Hello, >> However for some reason, when I click the button, in the callback I get a >> new elements RequestVar (so it's initialized to an initial value) and >> moreover, nothing gets redrawn on the page. What is also quite weird is that >> the RequestVar is re-initialized, but the snippet insta

Re: [Lift] Re: Ajax button + submitting a form

2010-01-11 Thread Naftoli Gugenheim
I don't think you need a SessionVar. You can just capture the RequestVar's value in a local val and refer to that in the closure. Basically if I understand correctly, this is a typical scenario where you output a form and associate functions with its fields which are to be executed on the *next*

Re: [Lift] Re: Ajax button + submitting a form

2010-01-11 Thread Adam Warski
Hello, this almost works :). Right now in my form I have a hidden element where the type of the operation to execute will be set: (the name is needed for jquery to set the value, and the id so that I can later read the value using S). I bind the button as following: "addElement" -> > JqAttr(

Re: [Lift] Re: Ajax button + submitting a form

2010-01-10 Thread Adam Warski
Hello, > ajaxButton("Press me would ya'?", SHtml.submitAjaxForm > (form_ID).toJsCmd, (some) => { > > do your stuff here > > }) Looking at the source code I think this might work, but I'm having trouble constructing the correct expression to pass to ajaxButton. The method signature requires a

Re: [Lift] Re: Ajax button + submitting a form

2010-01-10 Thread Adam Warski
right, I wrote about that in my original post, but how can I execute a button-specific method on the server-side? Thanks, Adam On Jan 10, 2010, at 12:15 PM, Marius wrote: > The ajax buttons doesn't have to be inside the form if you use > SHtml.submitAjaxForm(form_ID) > > blah > > Br's, > Mari

Re: [Lift] Re: Ajax button + submitting a form

2010-01-10 Thread Adam Warski
There is also a related problem: how can I have two ajax buttons on one form which submit the form and execute different functions on the server? Using the "standard" trick: SHtml.ajaxForm(bind(...) ++ SHtml.hidden(submitFunction)) won't work, as I want different functions executed for different

Re: [Lift] Re: Ajax button + submitting a form

2010-01-10 Thread Adam Warski
Hello, thanks, but my use-case is a bit different. I want the whole form to be still submitted using a POST (the "normal" way), and only use ajax for a small fragment of the page (the element editor). So I can't use ajaxForm(...), as this would make all submit buttons use ajax. Adam On Jan 9,