Changes to web2py.js - a bug(?) and request

73 views
Skip to first unread message

Ide

unread,
Sep 17, 2014, 3:09:47 PM9/17/14
to web...@googlegroups.com
Hi,

My posts from 15th Sept didn't seem to get approval to appear in the forum, so I'm assuming this was an oversight and posting 2 of them again in a single post this time.

I think there may be a bug in the web2py.js code (https://github.com/web2py/web2py/blob/master/applications/welcome/static/js/web2py.js#L263)

The relevant code is shown below, the condition appears to miss the situation where the form has no action attribute at all (url === 'undefined') and so does not use the component url in this case.

var url = form.attr('action');

if ((url === "") || (url === "#")) {
 
/* form has no action. Use component url. */
  url
= action;
}

I would suggest the code above is replaced with this:

var url = form.attr('action');

if ((url === "") || (url === "#") || (typeof url === 'undefined') {
 
/* form has no action. Use component url. */
  url
= action;
}

This seemed to fix the problem I was experiencing with forms in a component.

Also, I have been using this form of A helper (see code snippet below) in one of pages to update the content of a component, which works fine, however the 'data-w2p_remote' attribute of the component's DIV is not getting updated with the relevant URL used to update the content.

{{=A('linked page',_href='http://example.com',cid=request.cid)}

As a result, when a form gets loaded, the submitted form doesn't get sent to the original function with the correct request.args. Would it be possible to update web2py.js so that the component elements' 'data-w2p_remote' attribute get's updated. I think this would result in more consistent behaviour in ajax based applications. I have my own javascript code to do this for the time being, but it would be nicer to use web2py's own ajax code as this should take care of the intricate web2py ajax features.

Thanks.

Paolo Valleri

unread,
Sep 18, 2014, 1:14:37 AM9/18/14
to web...@googlegroups.com
Hi, 
I'd suggest to set url='' to fix your problem. While for second problem you should set ajax_trap=True for the LOAD helper. See http://web2py.com/books/default/chapter/29/12/components-and-plugins#LOAD-signature

Paolo

Ide

unread,
Sep 18, 2014, 5:16:37 PM9/18/14
to web...@googlegroups.com
Paolo,

Thanks for responding. I think you may misunderstand the issue with the first problem I describe. The code I have shown is part of the trap_form function included in web2py.js, not my own code. If the form doesn't have an action attribute set, then url does not get defined. It seems sensible to me for web2py.js to use the component URL in such a case, and would make the trap_form behaviour a little more robust.

For my second issue the original component is already loaded with ajax=True and ajax_trap=True. The problem is when I use a link generated by the A helper as suggested here: Trapped-Ajax-links-and-the-A-Helper. Now this link is in the main page, and I am trying to use it to update a component that has already been loaded, but the new content has an extra argument added on the the URL.

For example: The original component is loaded from http://example.com/myapp/myfunc.load, the trapped link refreshes this same component using /myapp/myfunc.load/test/ where test is the first argument (request.arg(0)), this will load a form. For my form submit to work, the new component url (as stored in data-w2p_remote) should now be /myapp/myfunc.load/test. As data-w2p_remote does not get updated when the trapped link is clicked my form gets submitted to /myapp/myfunc.load and so is missing the first argument that was available when the form was generated. Now I know I can get around this by explicitly setting the form's action attribute etc, but I think this is a work around and adds extra code, when a more elegant solution is possible.

I propose that when trapping the link in this way, that the data-w2p_remote should be updated, as this should represent the source of the current content of the component, not the original content. By not updating data-w2p_remote attribute, the client side DOM is now inconsistent in my opinion.

Regards,

Ide.

Massimo Di Pierro

unread,
Sep 20, 2014, 2:00:31 PM9/20/14
to web...@googlegroups.com
Please open a ticket about this.

Ide

unread,
Sep 22, 2014, 3:04:28 PM9/22/14
to web...@googlegroups.com
Massimo,

I have opened two tickets (#1986 and #1987) as these are two separate issues. I guess I should have done this first, but I hadn't looked at the issues list before.

Thanks.,

Ide.
Reply all
Reply to author
Forward
0 new messages