Skip to Content

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

How to check if control has a method?

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.

Tags:
replied

or even better

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

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question