Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Passing Parameters to Button Press Handler

Hi everyone.

The following code works:

var oDialog = new sap.ui.commons.Dialog();

oButton = new sap.ui.commons.Button();

oButton.setText("Close");

oButton.attachPress(HandleButtonClick);

oDialog.addButton(oButton);

                

// Open Dialog

oDialog.open();

function HandleButtonClick()

{    oDialog.close();        }

But this doesn't. Basically I'm trying to pass reference of oDialog, so that I can close it at a later stage.

var oDialog = new sap.ui.commons.Dialog();

oButton = new sap.ui.commons.Button();

oButton.setText("Close");

oButton.attachPress(HandleButtonClick(oDialog));

oDialog.addButton(oButton);

                

// Open Dialog

oDialog.open();

function HandleButtonClick(oDialog)

{    oDialog.close();        }

Thanks in advance guys.

Former Member
Former Member replied

Hi, yea I didn't test the code before I posted that... Sorry for that.

Take a look at the jsbin: https://jsbin.com/vinusub/edit?html,js,output

For if jsbin doesn't work for some reason:

var oDialog = new sap.ui.commons.Dialog(); 

oButton = new sap.ui.commons.Button(); 

oButton.setText("Close");

oButton.attachPress(function(oEvent){HandleButtonClick(oDialog);});

oDialog.addButton(oButton); 

//Open Dialog 

var open = new sap.ui.commons.Button({

  text:"Open dialog",

  press: function(){oDialog.open();}

});

function HandleButtonClick(oDialog){   

     oDialog.close(); 

}

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question