Search code examples
sapui5

Button Is Disabled but Still Listens to Press Event


I have a submit button in a <VBox>. On press of it, I have an order creation process. If I click multiple times on the button, multiple orders are created. Is there a way I can disable it after the first click?

I have written the following code in my controller, but it seems to be still hearing to the press action:

onSubmit: function(oEvent) { 
  this.getView().byId("save").setVisible(false);  
  //......
},

But this does not disable completely. Though in console, when I check using getEnabled(), it is set to false. How to stop the button from listening to press event when disabled?


Solution

  • I can suggest the following solutions:

    1. Right after the button got clicked - set its "enabled" property to "false" via property binding against JSON model. Once the async action got executed (i.e. success/fail callbacks) - release the button state by setting "enabled" to "true"
    2. Right after the button got clicked - set its "busy" property to "true" (do not forget to set the "busyIndicatorDelay" to 0. The releasing concept is the same as for point 1.

    In my opinion, these approaches are more UI5 specific. Personally I would choose the option 2, as it shows the state of processing something in a more prominent way to the user.