Our Blog

Let us find tech solutions together

Jul 19

Disabling an AJAX submit button

By kinabalu | Comments

 

A long running process that you’d like to show some indicator of progress or similar, usually means an indicator of some kind. Here we use an IndicatingAjaxButton to show some progress near the clicked submit button, and we use an IAjaxCallDecorator to disable the submit button so we don’t get multiple clicks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
form.add(new IndicatingAjaxButton("submit", form) {

    @Override
    protected IAjaxCallDecorator getAjaxCallDecorator() {
        return new AjaxPostprocessingCallDecorator(super.getAjaxCallDecorator()) {
            private static final long serialVersionUID = 1L;

            @Override
            public CharSequence postDecorateScript(CharSequence script) {
                return script + "this.disabled = true;";
            }
        };
    }
}