[web2py] cancel button

2010-02-06 Thread Jonathan Lundell
I seem to be full of elementary questions this week.

I've got a simple SQLFORM to add a row to a database, and I want to have a 
cancel button along with the submit button.

How?

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



[web2py] cancel button in update and create work differently

2010-05-31 Thread annet
I have a function to update opening hours:

@auth.requires_membership('homepage_manager')
def update_openinghours():
openinghours=db(db.openinghours.company_id==auth.user.company_id)\
.select(db.openinghours.ALL)
form=[]
if not openinghours or request.vars.x:
if not response.init_flash: response.init_flash='Insert
opening hour'
message='Opening hour inserted'
 
form=create_form(db.openinghours,'update_openingshours',message=message)
else:
if not request.args:
if not response.init_flash: response.init_flash='Opening
hours in database'
else:
if not response.init_flash: response.init_flash='Update
opening hour'
message='Opening hour updated'
 
form=update_form(db.openinghours,request.args[0],'update_openinghours',
\
message=message,deletable=True)
return dict(openinghours=openinghours,form=form)


In the create_form and update_form functions I add a cancel button to
the form which redirects to the current page:

def create_form(table,next,message):
 
form=crud.create(table=table,next=(URL(r=request,f=next)),message=message)
form[0][-1][1].append(INPUT(_type="button",_value="Cancel",\
_onclick="window.location='%s';"%URL(r=request,f=next)))
return form


def update_form(table,record,next,message,deletable):
 
form=crud.update(table=table,record=record,next=(URL(r=request,f=next)),message=message,deletable=deletable)
form[0][-1][1].append(INPUT(_type="button",_value="Cancel",\
_onclick="window.location='%s';"%URL(r=request,f=next)))
return form


In the view I have a link "insert record":

{{=A('Insert
record',_onmouseover="this.style.cursor='pointer';",\
_href=URL(r=request,f='update_openinghours',vars={'x':1}))}}


and the days are links:

 {{=A(record.dag,_onmouseover="this.style.cursor='pointer';",\
_href=URL(r=request,f='update_openinghours',args=[record.id]))}}



The problem is everything works accept for the cancel button in the
create_form, which results in an invalid function error when clicked.
This I don't understand, while the url's of the cancel buttons in both
the create_form and the update_form read the same, the cancel button
in the update_form works, the form above the table containing the
opening hours disappears and just the table is displayed.

I hope one of you knows why this happens and how I can fix this
problem.


Kind regards,

Annet.