Need help with the Jquery script in Lift

65 views
Skip to first unread message

sailor...@gmail.com

unread,
Aug 23, 2011, 9:42:11 PM8/23/11
to Lift
I remember I wrote another thread about this, and someone replied me
to write the codes. But I can't find the coding standard in Assembla,
so I write the codes with my style first.

1. TestForm.snippet
import _root_.net.liftweb._
import http._
import SHtml._
import util._
import Helpers._

class TestForm extends StatefulSnippet {
def dispatch = {
case _ => render
}

def render = "type=submit" #> SHtml.onSubmitUnit(() =>
println("TEST"))
}

2. test_1.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body class="lift:content_id=main">
<div id="main" class="lift:surround?with=default;at=content">
<div id="form" class="lift:TestForm?form=post">
<input id="submit" type="submit" value=" S U B M I T "/>
</div>
</div>
</body>
</html>

3. test_2.html (same with test_1.html but with the script in the
header )
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body class="lift:content_id=main">
<div id="main" class="lift:surround?with=default;at=content">
<head>
<script>
<script id="jquery" src="http://ajax.googleapis.com/ajax/libs/
jquery/1.6.1/jquery.min.js"
type="text/javascript"></script>
// <![CDATA[
jQuery(document).ready(function(){
jQuery("form").submit(function(){
jQuery(":submit").attr("disabled", "disabled");
});
});
// ]]>
</script>
</head>
<div id="form" class="lift:TestForm?form=post">
<input id="submit" type="submit" value=" S U B M I T "/>
</div>
</div>
</body>
</html>

4. My problem is, test_1 and test_2 calling the same StatefulSnippet
(TestForm), but in test_2 adding the script that prevents clicking
submit more than once, resulting the submit button doesn't work.
( Note : press submit in test_1.html I got the TEST message in
console, but not test_2.html )

Why? And what should I do to actually adding the javascript code to
work with Lift ?

Diego Medina

unread,
Aug 23, 2011, 10:34:42 PM8/23/11
to lif...@googlegroups.com
There is a Lift way of doing what you are trying to do,

from https://github.com/lift/framework/blob/master/web/webkit/src/main/scala/net/liftweb/http/S.scala

/**
* If you bind functions (i.e. using SHtml helpers) inside the
closure passed to callOnce,
* after your function is invoked, it will be automatically removed
from functions cache so
* that it cannot be invoked again.
*/
def callOnce[T](f: => T): T = {
autoCleanUp.doWith(true) {
f
}
}


Hope it helps

P.S. the code posting rules are here:

http://www.assembla.com/spaces/liftweb/wiki/Posting_example_code

Regards,

Diego

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

--
Diego Medina
Web Developer
(305) 788-4954
di...@fmpwizard.com
http://www.fmpwizard.com

sailor...@gmail.com

unread,
Aug 24, 2011, 5:13:30 AM8/24/11
to Lift
Thanks for the help, but I would like to ask the javascript code I
wrote is executed in the client first, and after that then it would be
posted to the server, why the server can't run the submit ?

Diego Medina

unread,
Aug 24, 2011, 3:36:05 PM8/24/11
to lif...@googlegroups.com

Could you post a sample app that shows the problem?

Thanks

Diego
Sent from my cell

Chka

unread,
Apr 24, 2012, 4:47:35 PM4/24/12
to lif...@googlegroups.com
Does anybody know how to make a submit button working with javascript code?

Any solution for the problem described above?



Thanks,
Chka

Diego Medina

unread,
Apr 24, 2012, 11:44:28 PM4/24/12
to lif...@googlegroups.com
On Tue, Apr 24, 2012 at 4:47 PM, Chka <chi...@gmail.com> wrote:
> Does anybody know how to make a submit button working with javascript code?

Could you be more specific about what you are trying to do? It doesn't
sound lift related, but maybe you meant something different than what
I think.

>
> Any solution for the problem described above?
>

I posted an answer to his question, you may want to start a new thread
with your own question.

Regards,

Diego


>
>
> Thanks,
> Chka
>
> --
> Lift, the simply functional web framework: http://liftweb.net
> Code: http://github.com/lift
> Discussion: http://groups.google.com/group/liftweb
> Stuck? Help us help you:
> https://www.assembla.com/wiki/show/liftweb/Posting_example_code

--
Diego Medina
Lift/Scala Developer
di...@fmpwizard.com
http://www.fmpwizard.com

Reply all
Reply to author
Forward
0 new messages