The onclick event doesn't cancel the standard submit behavior -- it just 
adds the onclick behavior before submitting. If you want to prevent the 
submit action, do:

_onclick='ajax("%s",[],":eval");return false'

"return false" prevents the submit. An alternative to using onclick is to 
register a jQuery event handler and call preventDefault() at the end of the 
handler. That is sometimes preferable because although it prevents the 
submit, it does not  stop the propagation of the event itself, in case 
there are other handlers set up to catch the same event ("return false" 
will prevent any other event handlers from being triggered).

Anthony

On Monday, June 25, 2012 6:13:31 AM UTC-4, weheh wrote:
>
> My controller has a componentized form with an added Cancel button 
> like this (this is an excerpt, so sorry for any typos):
>
> def update( ):
>
>   myform = SQLFORM.factory(
>     Field('text_in','text',requires=IS_NOT_EMPTY()),
>     buttons=[INPUT(_type='submit',_value=T('Update'))],
>     _id='myform',
>     formstyle='divs'
>     )
>   form.element('input[type=submit]').parent.append(
>     TAG.BUTTON(T('Cancel')),_onclick='ajax("%s",[],":eval");' % URL(
>         c='my_controller', f='cancel_update')
>     )
>   if myform.process(formanem='myform').accepted:
>     ...do stuff...
>  return dict(myform=myform)
>
>
>
> The form submits 
> properly when the Update button is pressed. However, when the Cancel 
> button is pressed, not only does 
> the "cancel_update" callback get called, the form also gets submitted 
> erroneously. The question is, why does the "update" action get called and 
> its form get submitted at all when the Cancel button is pressed?
>
>

-- 



Reply via email to