[RESOLVED] Suddenly can't get Parent ID in Event


#1

I have an event on right click, and when I trigger it, I have set the parent ID of the item I’m right clicking on my items attributes in the html.

Like this:

<span class="badge unitOnCall left" style="background: {{statusColor}}; color: {{textColor}};" callId="{{../_id}}" callNo="{{../callNo}}">{{unit}}</span>

In another event (double click) I get both the parent id and parent callNo with the following:

let callId = event.currentTarget.getAttribute('callId');
let callNo = event.currentTarget.getAttribute('callNo');

These both work flawlessly.

I have tried to use them in the event on right click, and get either null, or undefined.

I have also tried this._id which was working up until today, and now I only get null or undefined.

When I look in the inspector at the formed html for the element, it shows the proper _id for the parent as it should, so I don’t know why I’m suddenly unable to get this value on right click.

Any help, or thoughts are greatly appreciated.

Additionally, I tried,
<span class="badge unitOnCall left" style="background: {{statusColor}}; color: {{textColor}};" data-callid="{{../_id}}" callNo="{{../callNo}}">{{unit}}</span>

with

let callId = event.currentTarget.dataset.callid;

based on another post on the forums, but still no luck.


#2

Just to be clear, when you inspect the element, you see the proper data in each attribute? Have you tested across multiple browsers?


#3

No, haven’t tried with multiple browsers, and yes sir, I see the correct data in each attribute when I inspect.


#4

Hm, the next thing I’d try is logging the event.currentTarget to make sure your click is targeting correctly?


#5

Well, first of all if you want to get the data from the dataset your SPAN should have the attribute data-callid rather than just callid. And so on.

Can you maybe share your event handling code, including function(x,y)?


#6

<span class="badge js-myCall unitOnCall left" style="background: {{statusColor}}; color: {{textColor}};" data-callid="{{../_id}}" data-callNo="{{../callNo}}">{{unit}}</span>

(Note the added class ‘js-myCall’)

Template.xyz.events({
  "click .jsMyCall" : function(e,t){
      var callid = e.currentTarget.dataset.callid;
   }
})

#7

Sorry @ralof,

I have corrected my original post. The dataset-callid is how I have it, I just pasted the wrong section into the post.

I also use the uniOnCall as my identifying class (like you did with js-myCall.


#8

I believe it is targeting correctly. I get the console logging I expect for the event, but no data. I’ll try the console.dir of the event.currentTarget and see what I see.


#9

it should not be ‘dataset-callid’, just 'data-callid’
All the data- will then become the ‘dataset’ in the event


#10

ok, changed it to data-callid, but still get undefined.

I just don’t understand why on right-click I get undefined now, but with double click it’s working fine. I get all the data I expect.


#11

Show me your event handler code.


#12

No need. I got it again. Somehow…not sure what I did differently, but I’ll look back through with ‘undo’ and watch for a difference.

Thank you to all of you for your help, I appreciate it.