@Thiago: I'd like to inform my user that the form is currently being sent
(using an ajax request). That's why I need something similar to the
clickOnce example. Do you think that adding a validation error event isn't
a good idea anyway ? (It would probably serves other purpose for other
people)

@Harry: Your method is kind of the same as the jumpstart example and
therefore, it should break the form on validation error.

2014-12-01 19:56 GMT+01:00 Harry Zhou <superha...@gmail.com>:

> Below is the source of a ClickOnce mixin I wrote for 5.4.  Hopefully
> it helps.  Note that the mixin should be applied to a <form> element.
>
>
> 1.  Trivial java class
>
>
> package some.package.name.mixins; // Insert package name. That
> "mixins" has to be there.
>
> import org.apache.tapestry5.ClientElement;
> import org.apache.tapestry5.annotations.InjectContainer;
> import org.apache.tapestry5.annotations.MixinAfter;
> import org.apache.tapestry5.ioc.annotations.Inject;
> import org.apache.tapestry5.services.javascript.JavaScriptSupport;
>
> @MixinAfter
> public class ClickOnce {
> @Inject
> private JavaScriptSupport javaScriptSupport;
> @InjectContainer
>     private ClientElement clientElement;
>
> public void afterRender() {
> javaScriptSupport.require("clickOnce").with("#" +
> clientElement.getClientId());
> }
> }
>
> 2. JavaScript.  "clickOnce.js" should be a javascript file under the
> folder: src / main / resources / META-INF / modules /
>
> define(["jquery"], function($) {
>
>     return function(elementId) {
>
>     $(elementId).on("click", function(e) {
>
>     var element = $(this);
>
>     if(element.data("clicked") == true) {
>
>     element.prop("disabled", true);
>     e.preventDefault();
>
>     } else {
>
>     element.data("clicked", true);
>     if(element.is("a")) {
>     element.text("One moment ..."); // Change "One moment ..." to
> whatever prompt you like; use message catalogue for i18n.
>     element.addClass("disabled");
>     } else {
>     element.val("One moment ...");
>     }
>
>     }
>
>     });
>     }
>
> })
>
> That "e.preventDefault()" stops the form from emitting a submission event.
>
>
> 3. Like all JavaScript solutions, the above wouldn't work if
> JavaScript is somehow disabled in the user browser, and can be
> bypassed.  For server-end prevention of double-clicking, implement a
> token system that stores a random token in both session and as a
> hidden field (using <t:hidden>, etc.) in the form. The token in
> session gets immediately removed upon first use (token redemption).
> Subsequent token redemption for the same token should be ignored.
> This comes with the additional benefit of CSRF prevention.
>
>
> On Mon, Dec 1, 2014 at 1:26 PM, Thiago H de Paula Figueiredo
> <thiag...@gmail.com> wrote:
> > On Mon, 01 Dec 2014 16:05:02 -0200, Charlouze <m...@charlouze.com> wrote:
> >
> >> I'm not sure to understand what you mean... jumpstart example uses plain
> >> old js and does not work with tapestry client-side validation.
> >
> >
> > I mean something like
> >
> http://stackoverflow.com/questions/926816/how-to-prevent-form-from-submitting-multiple-times-from-client-side
> .
> >
> > $("form").submit(function() {
> >     $(this).submit(function() {
> >         return false;
> >     });
> >     return true;
> > });
> >
> > JumpStart's code you linked disables the button itself, which is an
> easier
> > way of showing how to write a mixin that uses JavaScript, while the one
> > above disables the second form submission itself.
> >
> >
> > --
> > Thiago H. de Paula Figueiredo
> > Tapestry, Java and Hibernate consultant and developer
> > http://machina.com.br
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> > For additional commands, e-mail: users-h...@tapestry.apache.org
> >
>
>
>
> --
> Best Regards
>     Harry Zhou
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>

Reply via email to