Skip to Content

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Oct 22, 2015 at 02:40 PM

    or even better

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

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 22, 2015 at 02:39 PM

    javascript is functional language


    so as easy as

    1. if( sap.ui.getCore().byId("<control's ID here>").getDateValue ) { 
    Add comment
    10|10000 characters needed characters exceeded