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