Hi,
> 3. As what I have tried, I find that the JsCmds only works fine when
> binding them to a html tag's onclick attribute. I have a function
> ()=>Any and it only has one statement, Alert("Hi!"), and I use it as
> the callback function of a button, SHtml.submit('doit',callback,...) , ...
First: Please make sure you have surrounded your NodeSeq with
SHtml.ajaxForm() when using ajax form.
SHtml.submit(..., callback ,...) // () => Any
SHtml.ajaxSubmit(..., callback ,...) // () => JsCmd
The compiler does not complain because JsCmd could also be an Any.
(Scala Class Hierarchy)
As you mentioned it they differ in functionality:
1. SHtml.submit asks: What function do I have to execute after the
form has been submitted and before the next page renders? (fire and
forget behaviour :))
2. SHtml.ajaxSubmit asks: What function do I have to execute after the
form has been submitted and what JavaScript commands do I need to
return to the client?
Have a closer look to the generated html:
1. <input type="submit" name="zF1251473096088GZV" value="Submit"/>
2. <input type="submit" onclick="liftAjax.lift_uriSuffix =
'zF1251473096088GZV=_'; return true;" name="zF1251473096088GZV"
value="Submit"/>
> JsCmds only works fine when binding them to a html tag's onclick attribute
That's true but not only onclick. It could be every possible
JavaScript event (onblur, onmouseover, ...)
I try to summarize it with a little example:
def hello : JsCmd = Alert("hello")
1. SHtml.a(() => hello, Text("click me")) // () => JsCmd
2. SHtml.a(Text("click me"), hello) // JsCmd
The first line will make a callback to the server. The server sends
back an alert("hello") which is executed on the client side.
The second one is already embedded in the html <a href="javascript:;"
onclick="alert('hello')" ... /> so no callback is made.
Daniel