vaadin / vaadin-button-flow

Vaadin Flow Java API for vaadin/vaadin-button Web Component
https://vaadin.com/components/vaadin-button
Other
0 stars 7 forks source link

disabledOnClick buttons can't be re-enabled #150

Closed robert-lee-hisl closed 4 years ago

robert-lee-hisl commented 4 years ago

The "setDisableOnClick" function is useful to stop the backend from spawning multiple threads in response to repeated mouse clicks on the button.

However, if the server returns synchronously, then the button is not enabled.

Using Vaadin 14.1.16

import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.router.Route;

@Route("button")
public class ButtonTest extends Button {

    public ButtonTest() {
        super("click me");
        addClickListener(e -> super.setDisabled(false));
        setDisableOnClick(true);
    }
}

The button should only be disabled while the client is communicating with the server, and re-enabled when "setDisabled(false)" is called, indicating that the server is ready for new work.

Instead, it remains disabled, because the server doesn't know that the disabled property has been set by this time, so it doesn't see a change in the disabled flag, so doesn't propagate it to the client.

Workaround is to put the "setDisabled(false)" into a background thread.

tomivirkki commented 4 years ago

Hi @robert-lee-hisl, instead of the protected setDisabled(false), use the public setEnabled(true)

robert-lee-hisl commented 4 years ago

@tomivirkki Thank you for your reply; setEnabled(true) does indeed seem to work.

It's odd, because setDisabled(false) has worked in previous versions, and makes more sense with the "setDisabledOnClick" nomenclature.