Skip to Content

CustomListItem press fires empty event after actual event is done

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/

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Aug 08, 2017 at 11:39 AM

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

    Regards,

    Jamie

    Add comment
    10|10000 characters needed characters exceeded

  • Aug 08, 2017 at 12:52 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • 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