You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by joris <jo...@web.de> on 2010/08/30 12:25:56 UTC

[T5] Prevent multiple form submits

Hello,

I try to prevent multiple form submits, if the user clicks more then
ones a submit button. 
Is there a build in way for this problem?
Or is there a preferred solution?

Thanks.
Joris




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [T5] Prevent multiple form submits

Posted by raulmt <ra...@gmail.com>.
I have an error in the second listener. It should be like this:

document.observe(Tapestry.TRIGGER_ZONE_UPDATE_EVENT, function(event) {
	var element = event.findElement();
	var zoneManager = Tapestry.findZoneManager(element);
	K12.showLoading(zoneManager.element);
});


Regards,
Raul.
-- 
View this message in context: http://tapestry-users.832.n2.nabble.com/T5-Prevent-multiple-form-submits-tp5477609p5484072.html
Sent from the Tapestry Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [T5] Prevent multiple form submits

Posted by raulmt <ra...@gmail.com>.
For example, you can listen to Tapestry.FORM_PROCESS_SUBMIT_EVENT to show the
div over the form, and then listen to Tapestry.ZONE_UPDATED_EVENT (this is
fired when you update the content of a Zone).

In order to put an overlay in all Zones, either associated with forms or
with links, you can observe this two events:

document.observe(Tapestry.FORM_PROCESS_SUBMIT_EVENT, function(event) {
	var form = event.findElement();
	var zoneManager = Tapestry.findZoneManager(form);
	K12.showLoading(zoneManager.element);
});

document.observe(Tapestry.TRIGGER_ZONE_UPDATE_EVENT, function(event) {
	var zone = event.findElement();
	K12.showLoading(zone.element);
});

Where K12.showLoading() creates or shows this overlay.

To remove the overlay, in most cases you can use the
Tapestry.ZONE_UPDATED_EVENT event, but this doesn't work well if your event
response from the server uses a MultiZoneUpdate (because this will trigger
Tapestry.ZONE_UPDATED_EVENT on every updated Zone and maybe that doesn't
include the Zone associated with the initial update trigger). So, what I did
was to decorate the method where the requesting Zone process the reply:

(function() {
	Tapestry.ZoneManager.addMethods({
		processReply:
Tapestry.ZoneManager.prototype.processReply.wrap(function(proceed, reply){
			proceed(reply);
			K12.hideLoading(this.element);
		})
	});
})();

in K12.hideLoading() I hide (or remove if you want to) the created overlay
(which is stored in a property inside the Tapestry object of the element (
$T(element) ) ).

I didn't like it too much to decorate this method, but it was the better way
I found. If anybody has a better way, please share :)

Regards,
Raul.
-- 
View this message in context: http://tapestry-users.832.n2.nabble.com/T5-Prevent-multiple-form-submits-tp5477609p5484015.html
Sent from the Tapestry Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [T5] Prevent multiple form submits

Posted by LLTYK <LL...@mailinator.com>.
I am wondering how I should handle ajax form submit. ClickOnce looks neat but
looks like it wouldn't work for that, and it looks like it might break with
client side validation too. I think I can see the events I need to observe
now, although I'm wondering how to hide my div again after an ajax submit
completes (or whether I should even show it for those forms). Wonder if a
form has it's zone in $T()...
-- 
View this message in context: http://tapestry-users.832.n2.nabble.com/T5-Prevent-multiple-form-submits-tp5477609p5482199.html
Sent from the Tapestry Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [T5] Prevent multiple form submits

Posted by raulmt <ra...@gmail.com>.
I don't know if I understand correctly your problem, but Tapestry fires some
JavaScript events when the form is submitting (see tapestry.js for details),
like Tapestry.FORM_VALIDATE_EVENT, Tapestry.FORM_PREPARE_FOR_SUBMIT_EVENT
and Tapestry.FORM_PROCESS_SUBMIT_EVENT. The latter two fire after
validation, so they are good to block another submission after the form has
passed validation and it is ready to submit.

Regards,
Raul.

P.S.: I use Tapestry.FORM_PREPARE_FOR_SUBMIT_EVENT to update a field
converted to TinyMCE, specially for Ajax submits (because it updates the
field automatically only on normal submits).

-- 
View this message in context: http://tapestry-users.832.n2.nabble.com/T5-Prevent-multiple-form-submits-tp5477609p5478598.html
Sent from the Tapestry Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [T5] Prevent multiple form submits

Posted by Sigbjørn Tvedt <si...@gmail.com>.
Have a look at this example (if javascript is an option):

http://jumpstart.doublenegative.com.au/jumpstart/examples/javascript/creatingmixins1

Sigbjørn Tvedt

On Mon, Aug 30, 2010 at 1:57 PM, joris <jo...@web.de> wrote:

> Yes, the client validation is the biggest problem. I tried something
> similar. I disable the submit button for 2 seconds, to work around the
> client site validation problem. I get it work for IE and Firefox, but in
> Chrome it doesn't work.
>
>  Event.observe(window, 'load', function() {
>        $$("input[type=submit]").each(function(submit) {
>                Event.observe(submit, 'click', function() {
>                        submit.disable();
>                         window.setTimeout(function() {
>                                 submit.enable();
>                         }, 2000);
>                         if(Prototype.Browser.IE){
>                                 submit.form.submit();
>                         }
>                });
>        });
> });
>
>
> Am Montag, den 30.08.2010, 04:14 -0700 schrieb LLTYK:
> > I have a hidden div with a "Processing" message, then I listen for submit
> > events and pop the div into view, blocking off the page until it
> redirects.
> > Although I haven't figured out how to get to mesh will with client side
> > validation, where I'd get an event but the form would not submit due to
> an
> > error (probably listening to wrong event).
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: [T5] Prevent multiple form submits

Posted by joris <jo...@web.de>.
Yes, the client validation is the biggest problem. I tried something
similar. I disable the submit button for 2 seconds, to work around the
client site validation problem. I get it work for IE and Firefox, but in
Chrome it doesn't work. 

 Event.observe(window, 'load', function() {
	$$("input[type=submit]").each(function(submit) {
		Event.observe(submit, 'click', function() {
			submit.disable();
			 window.setTimeout(function() {
				 submit.enable();
			 }, 2000);	
			 if(Prototype.Browser.IE){
				 submit.form.submit();
			 }
		});
	});
});


Am Montag, den 30.08.2010, 04:14 -0700 schrieb LLTYK:
> I have a hidden div with a "Processing" message, then I listen for submit
> events and pop the div into view, blocking off the page until it redirects.
> Although I haven't figured out how to get to mesh will with client side
> validation, where I'd get an event but the form would not submit due to an
> error (probably listening to wrong event).


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [T5] Prevent multiple form submits

Posted by LLTYK <LL...@mailinator.com>.
I have a hidden div with a "Processing" message, then I listen for submit
events and pop the div into view, blocking off the page until it redirects.
Although I haven't figured out how to get to mesh will with client side
validation, where I'd get an event but the form would not submit due to an
error (probably listening to wrong event).
-- 
View this message in context: http://tapestry-users.832.n2.nabble.com/T5-Prevent-multiple-form-submits-tp5477609p5477739.html
Sent from the Tapestry Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org