Hello I am trying to handle an event in my lightning component between 2 items being dragged and dropped onto another.
My event seems to be firing, however it is not being handled as the function that is supposed to be called by the action parameter is not returning any console messages.
Component with the register.
<aura:component >
<!-- Custom Events -->
<aura:registerEvent name="cardSwapRegister" type="c:CardSwap"/>
Controller that fires the event
onDrop: function(component, event, helper)
{
event.preventDefault();
var cardSwapEvent = component.getEvent('cardSwapRegister');
cardSwapEvent.setParams({'seatName': component.get('v.seatName'),
'seatId': component.get('v.seatId'),
'item': JSON.parse(event.dataTransfer.getData('text'))});
console.log("Target Seat Name: ", component.get('v.seatName'));
console.log("Target Seat Id: ", component.get('v.seatId'));
cardSwapEvent.fire()
}
CardSwap.evt
<aura:event type="COMPONENT" description="Event fired when 2 cards collide with each other">
<aura:attribute name="item" type="Object" required="true"></aura:attribute>
<aura:attribute name="seatName" type="String" required="true"></aura:attribute>
<aura:attribute name="seatId" type="String" required="true"></aura:attribute>
</aura:event>
Component/Handler
<aura:component controller="DragDropApexController" >
<aura:handler name="cardSwapped" event="c:CardSwap" action="
{!c.onPersonMoved}"></aura:handler>
</aura:component>
Controller that is not being called by the handler
onPersonMoved: function(component, event, helper)
{
console.log("Swapping...");
var item = event.getParam("item"); //This is the item that was moved.
//Code here to swap the seat information
//z = x;
//x = y;
//y = z;
},
var
any more. Useconst
orlet
instead.const
andlet
. So why would that be relevant?let
, though, with a note saying "let variables are not bound separately to each iteration of for loops" caniuse.com. So, one still needs to be careful about potential side effects.