Instead of adding two identical click even handlers, maybe it would work to
use the jQuery .live() method to add the handler just once (when the main
page is loaded). The .live() method will handle events even on DOM elements
that are added to the page after the handler is initiated -- see
http://api.jquery.com/live/. This way, you shouldn't need response.js.
Anthony
On Monday, December 3, 2012 10:26:47 AM UTC-5, Richard wrote:
>
> Hello,
>
> I read in the book that response.js should be use to insert javascript
> stuff that should be executed in context of a LOAD component. My
> understanding is that the piece of javascript embeded in the component
> should be executed only in the component... But under web2py 221 I can get
> this jQuery code executed no matter if the form is the one of the component
> or the main form of the page :
>
> jQuery(document).ready(function () {
> jQuery(".icon-calendar").click(function()
> {$(this).parent().prev().click().focus();});
> });
>
> Detailed explanation :
>
> # Controller
> def main_form():
> form = SQLFORM(db.table1)
> return dict(form=form)
>
> def embeded_form():
> form = SQLFORM(db.table2)
> response.js = 'jQuery(document).ready(function () {
> jQuery(".icon-calendar").click(function()
> {$(this).parent().prev().click().focus();}); });'
> return dict(form=form)
>
> # View
> main_form.html
>
> {{=form}}
> {{=LOAD(c='controller', f='embeded_form', ajax=True)}}
> <script>
> jQuery(document).ready(function () {
> jQuery(".icon-calendar").click(function()
> {$(this).parent().prev().click().focus();});
> });
> </script>
>
> Doesn't matter if I comment out the jQuery below, I still have it to work
> for the main form and the embeded form component. If I remove the
> reponse.js jquery, I only get the main form to work properly. But the
> embeded form calendar won't show up.
>
> The problem is that if I put the script in the view of the main_form and
> in the respons.js, when I click on the icon calendar of the main (only) I
> get many instance of the form that show up that get stacked at the end of
> the page.
>
> Thanks
>
> Richard
>
--