When I want to cancel the submission of a form in tapestry via javascript I set the event's abort and cancel_handlers properties appropriately.
tapesty passes your ${checkSubmit} method an event 'object' that has the above mentioned properties. returning false from a handler like this won't have the effect you want. The onSubmit function provided by tapestry has 'return true;' hardcoded into it unless you abort the event. declare the event parameter to the function, then when you want to stop the form from submitting, execute the code 'event.abort = true;'. If you also want to prevent additional handlers from being called (other submit or ANY postsubmit), execute the code 'event.cancel_handlers = true'; NOTE TO TAP DEVELOPERS: This needs to work so that returning false from any of the three handler types (presubmit, submit, postsubmit) causes the submission of the form to stop just as it would in normal flow. -Mike On 4/12/06, Dan Adams <[EMAIL PROTECTED]> wrote: > Okay, I've got the common problem where I want to prevent some users > from double clicking submit buttons and double submitting a form. I've > got the following script which seems to work except that it seems to > miss one of the clicks. If you double click, it still double submits the > form. If you triple click, however, it double submits like before but > then you get an alert that says 'already submitted 2' meaning that > checkSubmit() has only been called twice. Is there something I'm > missing? Thanks. > > <script> > <input-symbol key="form" class="org.apache.tapestry.form.Form" > required="yes" /> > > <let key="checkSubmit" unique="yes">checkSubmit</let> > <let key="submitted" unique="yes">submitted</let> > > <body><![CDATA[ > var ${submitted} = false; > var count = 0; > > // ensures that the form is only submitted once > function ${checkSubmit}() { > var ret = true; > count++; > > if (${submitted} == true) { > alert('already submitted ' + count); > ret = false; > } > > ${submitted} = true; > return ret; > } > > ]]></body> > > <initialization><![CDATA[ > Tapestry.onsubmit('${form.name}', ${checkSubmit}); > ]]></initialization> > > </script> > > -- > Dan Adams > Software Engineer > Interactive Factory > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]