I've been playing around with it a bit more, and it seems to be the same 
underlying problem that Anthony described above. The question is: why 
doesn't the formname fix work for ajax components?

On Monday, 22 April 2013 09:19:06 UTC+1, Neil wrote:
>
> Thanks for that. Unfortunately, there seems to be a little more to it. 
>
> He is a minimal example (using web2py 2.4.6/rocket/windows, although 
> the behavior is the same with other configurations).
>
> controllers/default.py:
>
> def index():
>     return dict()
>
> def f1():
>     val1 = ""
>     form1 = FORM('Form 1 input:', INPUT(_name='f1input', requires=
> IS_NOT_EMPTY()), INPUT(_type='submit'))
>     if form1.accepts(request,session,formname="formname1"):
>         val1 = form1.vars.f1input
>     elif form1.errors:
>         response.flash = 'Form 1 has errors'
>     return dict(form1=form1, val1=val1)
>
> def f2():
>     val2 = ""
>     form2 = FORM('Form 2 input:', INPUT(_name='f2input', requires=
> IS_NOT_EMPTY()), INPUT(_type='submit'))
>     if form2.accepts(request,session,formname="formname2"):
>         val2 = form2.vars.f2input
>     elif form2.errors:
>         response.flash = 'Form 2 has errors'
>     return dict(form2=form2, val2=val2)
>
> views/default/f1.load:
>
> <p>{{=val1}}</p>
> {{=form1}}
>
> views/default/f2.load:
>
> <p>{{=val2}}</p>
> {{=form2}}
>
> views/default/index.html:
>
> {{extend 'layout.html'}}
> {{=LOAD('default','f1.load',ajax=True)}}
> {{=LOAD('default','f2.load',ajax=True)}}
>
>
> The behavior is unpredictable. Sometimes the first submit for form 1 
> doesn't do anything.  You may need to refresh several times to reproduce.
>
> Bug, or I have I done something wrong?
>
> Neil
>
> On Sunday, 21 April 2013 20:19:25 UTC+1, Anthony wrote:
>>
>> Probably both forms have the same formname, either because they are both 
>> based on the same DAL table or because they are both SQLFORM.factory forms. 
>> To avoid the problem, assign unique formnames to each via 
>> .process(formname='myform1'), etc. This is discussed in the book: 
>> http://web2py.com/books/default/chapter/29/07#Multiple-forms-per-page.
>>
>> Note, the problem isn't really limited to multiple forms on the same 
>> page, but to multiple forms with the same name in the same browser session 
>> (even if loaded into different tabs/windows that are open at the same 
>> time). The problem is that the value of the formkey is stored in the 
>> session with a key like "_formkey[formname]". If a second form is created 
>> before the first form has been submitted, the formkey associated with that 
>> particular formname will be overwritten, so when the first form is 
>> submitted, it will not be accepted. However, the submission itself will 
>> once again replace the formkey value, so if you immediately submit a second 
>> time, it will work.
>>
>> Anthony
>>
>> On Sunday, April 21, 2013 5:03:06 AM UTC-4, Neil wrote:
>>>
>>> I'm having this problem now - is there a trick to having two ajax forms 
>>> on one page?
>>>
>>> Basically, as above, I have to hit submit twice for anything result. Has 
>>> anyone successfully had 2+ ajax forms on the same page?
>>>
>>> On Wednesday, 21 July 2010 08:37:54 UTC+1, mdipierro wrote:
>>>>
>>>> will look into this.. it must be a JS issue. 
>>>>
>>>> On Jul 20, 9:10 pm, ionel <[email protected]> wrote: 
>>>> > Hello, 
>>>> > 
>>>> > I try to add two ajax forms into a page with something like this: 
>>>> > 
>>>> > {{=LOAD(url=URL(r=request,f='add_person.load'), ajax=True)}} 
>>>> > {{=LOAD(url=URL(r=request,f='add_image.load'), ajax=True)}} 
>>>> > 
>>>> > If the form has errors, the error messages are displayed after a 
>>>> > second submit. So, I need to click two times the submit button to 
>>>> > display them. 
>>>> > 
>>>> > The second form has a normal behavior. 
>>>> > 
>>>> > Thanks. 
>>>> > 
>>>> > i.a.
>>>
>>>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to