Wizard inside a LOAD

72 views
Skip to first unread message

Jose

unread,
Sep 30, 2015, 10:00:06 PM9/30/15
to web2py-users
Hi

I am embedding wizard in a LOAD

{{=LOAD('default', 'f1', ajax=True, ajax_trap=True)}}



def f1():
    form
= FORM(...)

   
if form.process().accepted:
       
#I do something
        redirect
(URL('f2'))
   
   
return form




def f2():
    form
= FORM(...)

   
if form.process().accepted:
       
#I do something
        redirect
(URL('f3'))
   
   
return form




def f3():
    form
= FORM(...)

   
if form.process().accepted:
       
#I do something
        redirect
(URL('f_end'))
   
   
return form



After submit in f1, works well and redirects to f2, but when you submit in f2 does what I expect and redirects to f1 (should redirect to f3)

Any idea how to fix it

Best Regards,
José

Jose

unread,
Oct 1, 2015, 2:21:50 PM10/1/15
to web2py-users
I found this [1] and [2]. it seems that with some modifications on an old version of web2py work (web2py.js and web2py_ajax.html), but I can not fix it in new versions

José


[1] https://groups.google.com/forum/?fromgroups#!topic/web2py/J7-SD0n8hQQ
[2] https://groups.google.com/forum/#!msg/web2py/N414q0pH7W0/pB7zIbC-fzMJ

Niphlod

unread,
Oct 1, 2015, 3:34:20 PM10/1/15
to web2py-users
getting on it...

Niphlod

unread,
Oct 1, 2015, 5:10:17 PM10/1/15
to web2py-users
umpf. the behaviour is reproducible.
The thing is, handling component redirects with ajax as normal redirects is bad because ajax just follow the same convention as browsers and it's impossible to intercept a get wich follows a redirect from a normal get in any way.

For now the proposed fix/workaround is to pass an explicit _action to the FORM, which will prevail if explicitely found.
Its quite easy because _action=URL() gets things done pretty quickly and painless.

Now, for the "real fix", we'd have either to add an header to every ajax or we won't be able to distinguish a 200 from a 302+200.
I'm open to possible solutions not involving add an header to every ajax request. 

Niphlod

unread,
Oct 1, 2015, 6:00:17 PM10/1/15
to web2py-users
proposed fix:

gluon.main : 
just after setting web2py-component-command, set a new web2py-component-origaction header = request.url

web2py.js : 
in ajax_page, inside oncomplete, just before web2py.trap_form, handle it

var origaction = xhr.getresponseheader('web2py-component-origaction');
action = (typeof origaction != 'undefined') ? origaction : action;

and it works.
Just for completeness, same type of handling in updatePage to change the w2p_remote of the cid to web2py-component-origaction

Of course, this stands as long as there's really no method to extrapolate on the oncomplete callback the "final url" that has been loaded, in which case, no gluon.main changes necessary.

Jose

unread,
Oct 2, 2015, 8:48:27 AM10/2/15
to web2py-users



For now the proposed fix/workaround is to pass an explicit _action to the FORM, which will prevail if explicitely found.
Its quite easy because _action=URL() gets things done pretty quickly and painless.

this has not worked

Niphlod

unread,
Oct 2, 2015, 6:49:52 PM10/2/15
to web2py-users
tested and retested. it works. please inspect your form and see if the correct url is generated and put in the action attribute.

Jose

unread,
Oct 5, 2015, 12:04:29 PM10/5/15
to web2py-users


El viernes, 2 de octubre de 2015, 19:49:52 (UTC-3), Niphlod escribió:
tested and retested. it works. please inspect your form and see if the correct url is generated and put in the action attribute.



You are right. It works. But in my case it will not work because it is not linear but follows a branching process.

Thank you so much

José

Reply all
Reply to author
Forward
0 new messages