cancel
Showing results for 
Search instead for 
Did you mean: 

How to check if control has a method?

dunayevsky_yuri
Participant
0 Kudos

Hello,

I'm trying to find out how do I check if a given control has a method I look for.

For example, I have 2 controls:


var oControl1 = new sap.m.DateTimeInput({

     id: "control1",

     type: "DateTime"

});

var oControl2 = new sap.m.Input({

     id: "control2",

     type: "Number"

});

The first control has getDateValue() method, which the second one doesn't.

I want to check if the control I call using dynamic ID has a specific method, like (this is not a real code, it's how I want to check):


if(sap.ui.getCore().byId("<control's ID here>").hasMethod("getDateValue")){

     alert("Hurray!");

}

Is there a way do accomplish this?

Thank you.

Accepted Solutions (1)

Accepted Solutions (1)

former_member182372
Active Contributor

or even better

            if (typeof sap.ui.getCore().byId("<control's ID here>").getDateValue == 'function') {

dunayevsky_yuri
Participant
0 Kudos

It's perfect, thank you!

Regards,

Yuri

Answers (1)

Answers (1)

former_member182372
Active Contributor
0 Kudos

javascript is functional language


so as easy as

  1. if( sap.ui.getCore().byId("<control's ID here>").getDateValue ) {