Thanks for all the help.
I've just figured out how to get this working. Here's the mixin code in case
anyone needs similar functionality:

@Import(library = "disableAfterSubmit.js")
public class DisableAfterSubmit {
    @Inject
    private JavaScriptSupport javaScriptSupport;

    @InjectContainer
    private ClientElement element;

    @Environmental
    private FormSupport formSupport;

    /**
     * Adds content to the bottom of the component.
     */
    @AfterRender
    public void afterRender() {
        javaScriptSupport.addScript(String.format("new
DisableAfterSubmit('%s', '%s');", element.getClientId(),
formSupport.getClientId()));
    }
}

disableAfterSubmit.js

var DisableAfterSubmit = Class.create();
DisableAfterSubmit.prototype = {

    initialize: function(elementId, formId) {
        this.formId = formId;
        this.elementId = elementId;

        Event.observe($(elementId), 'click',
this.doDisable.bindAsEventListener(this));
    },

    doDisable: function(e) {
        $(this.elementId).disable();
        $(this.formId).onsubmit();
    }
}

On Tue, Nov 23, 2010 at 13:01, Newham, Cameron <cameron.new...@bl.uk> wrote:

> It's exactly this kind of thing that should appear as an example on the
> new website.
>
> c.
>
> -----Original Message-----
> From: Inge Solvoll [mailto:inge.tapes...@gmail.com]
> Sent: 23 November 2010 12:36
> To: Tapestry users
> Subject: Re: Disabling submit button after click
>
> Easy:
>
> Create a mixin that:
> - uses javascript to apply "disabled"-looking css styles when clicking
> the
> button
> - hooks a javascript handler to the button that cancels future submits.
> - on AJAX return, revert 2 previous actions from a javascript listener.
>
> On Tue, Nov 23, 2010 at 12:56 PM, Hugo Palma <hugo.m.pa...@gmail.com>
> wrote:
>
> > I would like to disable a form submit button after click in order to
> avoid
> > multiple clicking.
> > This can easily be done by calling "this.disabled = true" on the
> onclick
> > event of the button but this also prevents the submit event from
> executing.
> >
> > I could do "this.disabled = true;form.submit()" but in my case i have
> an
> > ajax form with the zone parameter and the form.submit() forces the
> "normal"
> > submit with full page reload.
> > So, any idea how i can disable the submit button and not cancel the
> ajax
> > form submit ?
> >
> > Thanks,
> > Hugo
> >
> > --
> >
> > LinkedIn <http://www.linkedin.com/in/hugopalma>
> > Twitter<http://twitter.com/hugompalma>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>


-- 

LinkedIn <http://www.linkedin.com/in/hugopalma>
Twitter<http://twitter.com/hugompalma>

Reply via email to