solved this with the following code as you suggested:
populate() fills some data in according tables and does also del
session.tmpstation
i've added a timeout also, user can refresh or reopen the url from a faulty
action such as closing page etc
def confirm():
TIMEOUT=60*2
if session.tmpstation:
if not session.laststation<time.time()-TIMEOUT:
..setting default values for fields..
else:
del session.tmpstation
redirect(URL('add'))
else:
redirect('add')
#form = crud.create(db.stations, next=URL('index'), message=T("record
created"))
form = SQLFORM(db.stations).process(next=URL('populate'),
message_onsuccess=T("record created"), message_onfailure=T("Failed"))
form.element(_type='submit')['_onclick'] = "msg=''"
script=SCRIPT("setTimeout(function(){var msg='Form will be erased and
you will be prompted at add page';window.onbeforeunload = function() "
"{if (msg!='') {return
msg;}};},"+str(TIMEOUT*1000+session.laststation*1000-int(time.time()*1000))+");")
return dict(form=form+script)
: confirm.html
{{extend 'layout.html'}}
{{=form}}
for the next steps i think that i have to "merge" add() & confirm() in the
same controller/page and make populate() accessible from
.process(onsuccess=populate)
On Tuesday, August 6, 2013 10:10:03 PM UTC+3, Niphlod wrote:
>
> you need to hook up to the submit event of the form and disabling what you
> added as onbeforeunload.
> Lots of examples around, e.g.
> http://stackoverflow.com/questions/1973708/how-to-prevent-onbeforeunload-from-being-called-when-clicking-submit-button
>
>
> On Tuesday, August 6, 2013 8:54:15 PM UTC+2, Antonis Konstantinos Tzorvas
> wrote:
>>
>> def add():
>> form = SQLFORM.factory(Field('url', 'string'))
>>
>> if form.process().accepted:
>> mystation = info.station(form.vars.url)
>> session.tmpstation = mystation
>> redirect(URL('confirm'))
>> return dict(form=form)
>>
>>
>> def confirm():
>> ... prepopulating form with vars from vars(session.tmpstation) ...
>> form = SQLFORM(db.stations).process(next=URL('populate'),
>> message=T("record created"))
>> del session.tmpstation
>> return dict(form=form)
>>
>> .... confirm.html
>> {{extend 'layout.html'}}
>> {{=form}}
>> <script>window.onbeforeunload = function() {return "form will lose all
>> data";};</script>
>>
>> is there any way to prevent onbeforeunload if form.submit() is the event
>> triggering the "onbeforeunload"?
>>
>
--
---
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.