LockerService - event.target is SecureObject instead of SecureElement when html is inside iteration or if
Last updated 2016-12-08 ·Reference W-3206803 ·Reported By 10 users
Summary
When html elements are nested inside an aura:iteration or aura:if they are keyed to the iteration now, instead of the containing component. So when you click on an element inside the iteration the event.target doesn't match keys to the component and we get back SecureObject instead of SecureElement like before.
Repro
1) Login the Org
2) Create the following elements:
APEX CONTROLLER:
Global class TestLockerServiceController {
@AuraEnabled
public static List<Account> Getaccounts()
{
return [SELECT id,name from Account limit 4];
}
}
// COMPONENT:
<aura:component controller="TestLockerServiceController" implements="flexipage:availableForAllPageTypes">
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<aura:attribute name="accounts" type="account[]" />
<table><tr>
<aura:iteration items="{!v.accounts}" var="acct" indexVar="indx">
<button onclick="{!c.handleclick}" class='img' data-id='{!acct.id}'>{!acct.Name}</button>
</aura:iteration>
</tr></table>
</aura:component>
//CONTROLLER
({
doInit : function(component, event, helper) {
helper.getaccounts(component,event);
},
handleclick:function(component, event){
debugger;
var target = event.target.getAttribute('data-id'); //(ITS FAILING HERE)
}
})
//HELPER
({
getaccounts : function(component,event) {
var action = component.get("c.Getaccounts");
var self = this;
action.setCallback(this, function(a) {
debugger;
component.set("v.accounts", a.getReturnValue());
});
$A.enqueueAction(action);
}
})
Actual Result
=====================
Error Message:
Something has gone wrong. Action failed: c$FieldProCalendarRowComponent$controller$handleDrop [TypeError: event.getSource is not a function] Failing descriptor: {c$FieldProCalendarRowComponent$controller$handleDrop}. Please try again.
Expected Result
=====================
Lightning Component should work as before the Locker Service Critical Update was automatically enabled.
Workaround
No workaround.
Is it Fixed?
Any unreleased services, features, statuses, or dates referenced in this or other public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make their purchase decisions based upon features that are currently available.