cancel
Showing results for 
Search instead for 
Did you mean: 

How to register function for an event control?

0 Kudos

Hey there,

I'm looking for a way to subscribe a function for a specific events of a control.

In my scenario there is provided the method attachSearch() for the control FilterBar that attaches event handler fnFunction to the 'search' event. But strangely enough while I'm calling this method by following line just calls my onMyMethod directly.


this._oSmartFilter.attachSearch(this.onMyMethod(oEvent));

After raising the event "search" the following error is returned:

Uncaught TypeError: Cannot read property 'call' of undefined

Any ideas?

Thanks for your help in advance.

Robert

Accepted Solutions (1)

Accepted Solutions (1)

saivellanki
Active Contributor
0 Kudos

Hi Robert,

Please correct, if my understanding is wrong.

Is this what you're expecting?


var that = this;

this._oSmartFilter.attachSearch(function(oEvent){

  that.onMyMethod(oEvent);

});

Regards,

Sai Vellanki.

0 Kudos

Hey Sai,

Thanks for your reply.

I tried your code but it ends with following error in the console:

Uncaught RangeError: Maximum call stack size exceeded

Best regards...

saivellanki
Active Contributor
0 Kudos

Robert,

Did you try this one as well?


this._oSmartFilter.attachSearch($.proxy(this.onMyMethod(oEvent), this));

(or)



this._oSmartFilter.attachSearch[this.onMyMethod(oEvent), this]


Regards,

Sai Vellanki.

former_member182862
Active Contributor
0 Kudos

Hi Robert

the error message means that you code enter an indefinite loop.

Alternative to Sai answer, here is another one

this._oSmartFilter.attachSearch(function(oEvent) {
    this.onMyMethod(oEvent)
}.bind(this));

-D

0 Kudos

Hey Dennis,

After trying yours, I do get followng console message:

Uncaught TypeError: this.onMyMethod is not a function

Strangely underneath where I did call your code I declared my method but this is not found . On the whole it looks as follows:

init: function(oEvent, aServiceOrders) {

    this._oSmartFilter.attachSearch(function(oEvent) { this.onMyMethod(oEvent).bind(this); });

}

onMyMethod: function(oEvent, aServiceOrders) {


}

former_member182862
Active Contributor
0 Kudos

HI Bob


this._oSmartFilter.attachSearch(function(oEvent) { this.onMyMethod(oEvent).bind(this); });


should be

this._oSmartFilter.attachSearch(function(oEvent) { this.onMyMethod(oEvent); }.bind(this));

0 Kudos

Hey Dennis,

That's knotty!

You're right, I used an incorrect line but now the infinity loop shows up again:

Uncaught RangeError: Maximum call stack size exceeded

It seems to call my onMyMethod endlessly

Any help is very appreciated...

former_member182862
Active Contributor
0 Kudos

in your onMyMethod, do you change the view of the filter? If yes, then it will run into a loop.

You can use the debugger in your browser to figure out what is looping

-D

0 Kudos

Argh... Misleadingly I did use the search() method to retrieve the event "search". Now it's working. Many thanks, Dennis!

Answers (1)

Answers (1)

Former Member
0 Kudos

Hello Robert,

Want you need to do is just pass the function that you want to be called rather than execute it directly.

this._oSmartFilter.attachSearch(this.onMyMethod); is the proper way to do it.

0 Kudos

Hey Deyan,

That's not point! The problem with your approach is that the onMyMethod method is not found by simply calling it through attachSearch.

Anyhow, thanks for your reply...