cancel
Showing results for 
Search instead for 
Did you mean: 

CustomListItem press fires empty event after actual event is done

philipp_thiele
Explorer
0 Kudos

Hi everyone,

I have a sap.m.list in which I create CustomListItems through binding.

The CustomListItem has the press event:

<CustomListItem type="Active" press="onListItemClicked">

As soon as I add this press event in the XML view (it doesn't matter if I use the event in controller or I don't) I get an error when clicking on a list item:

Uncaught TypeError: Cannot read property 'call' of undefined
    at f.a.fireEvent (EventProvider-dbg.js:229)
    at f.a.fireEvent (Element-dbg.js:427)
    at f.fireItemPress (ManagedObjectMetadata-dbg.js:426)
    at f.eval (eval at evalModuleStr (jquery.sap.global-dbg.js:3395), <anonymous>:2546:129)
    at jquery.sap.script-dbg.js:64

The thing is: my event works just fine, but I don't want the error to be thrown every time someone clicks on an item.

I set a break point on EventProvider-dbg.js:229. The line says:

oInfo.fFunction.call(oInfo.oListener || oProvider, oEvent, oInfo.oData);

I noticed, that this line runs twice: First time it works fine and oInfo has a defined fFunction. Then my event handler is called and everything works. The second time the fFunction is undefined, the error is thrown and the execution stops.

Does anyone have an idea why this could happen?

Thank you and best regards,

Philipp

EDIT:

I'm using SAP UI5 Version 1.46.11.

I tried to recreate the error on jsfiddle using the exact same controls. The problem doesn't exist there, so it must be something more fundamental. Any ideas how I could debug this/where I could take a look?

https://jsfiddle.net/qjw6u4xp/

Accepted Solutions (0)

Answers (2)

Answers (2)

Sharathmg
Active Contributor
0 Kudos

For some reason, the event is being called again. Try to subscribe for event - selectionChange, which is specific to any change by user in the list item selection.

Regards,

Sharath

philipp_thiele
Explorer
0 Kudos

I'm not using the event of the list, I'm using the press event from the items. Should work as well though, right?

I added a jsfiddle above, but wasn't able to reproduce the error.

Sharathmg
Active Contributor
0 Kudos

Ideally should but seems like its getting registered twice. To avoid it, use an event specific to the list - usually when an item is pressed(itempress) or when a change in selection of items in the list(selectionChange).

Regards,

Sharath

jamie_cawley
Advisor
Advisor
0 Kudos

What UI5 version are you using? Please provide your code too.

Regards,

Jamie

philipp_thiele
Explorer
0 Kudos

I'm using 1.46.11.

I tried to recreate the error minified here. I used exactly the same controls as in my application:

https://jsfiddle.net/qjw6u4xp/

The problem is, it just works there. So I must have another problem I didn't think about.

Any ideas where/in which direction I could take a look?

jamie_cawley
Advisor
Advisor
0 Kudos

I would need to see your code.

Regards,

Jamie