so I have this component called "Tag" nested inside another component called "TagSelect".
After some user action, Tag raises an event, handled by TagSelect, which then executes an action.
The event is well raised by Tag, well handled by TagSelect, bu then the action is enqueued, but never executed.
The action is supposed to call some apex code to remove a record from the database.
TagRemoveEvent :
<aura:event type="COMPONENT" description="Fired when removing a Tag">
<aura:attribute name="tagId" type="String" required="true" />
<aura:attribute name="tagRecordId" type="String" required="true" />
</aura:event>
Tag :
<aura:attribute name="tagName" type="String" required="true" />
<aura:attribute name="tagId" type="String" required="true" />
<aura:attribute name="tagRecordId" type="String" required="true" />
<aura:registerEvent name="TagRemoveEvent" type="c:TagRemoveEvent" />
<span class="slds-pill" style="margin-top: 5px; color: #0070d2;">
<a onclick="{!c.removeMe}">x</a>
{!v.tagName}
</span>
</aura:component>
TagController :
({
removeMe : function(component, event, helper) {
console.log('fired! 1'); // displayed in console
var cmpEvent = component.getEvent('TagRemoveEvent');
cmpEvent.setParams({
tagRecordId: component.get('v.tagRecordId'),
tagId: component.get('v.tagId')
});
cmpEvent.fire();
}
})
TagSelect :
<aura:component implements="flexipage:availableForAllPageTypes,force:hasRecordId,force:recordTab" controller="TagSelectController">
<ltng:require styles="/resource/SLDS105/assets/styles/salesforce-lightning-design-system-ltng.css,/resource/JQueryUICSS"
scripts="/resource/JQueryJS,/resource/JQueryUIJS"
afterScriptsLoaded="{!c.doInit}" />
<aura:attribute name="bRender" type="Boolean" default="false" />
<aura:attribute name="tags" type="Tag[]" />
<aura:handler name="TagRemoveEvent" event="c:TagRemoveEvent" action="{!c.removeTag}" />
// some code
<aura:iteration items="{!v.tags}" var="tag">
<c:Tag tagName="{!tag.tagName}" tagId="{!tag.tagId}" tagRecordId="{!tag.tagRecordId}" />
</aura:iteration>
// some code
</aura:component>
TagSelectController :
({
doInit : function(component, event, helper) {
/* some code */
},
removeTag : function(component, event, helper) {
console.log('fired! 2'); // displayed in console
var parentId = event.getParam("tagRecordId");
var tagId = event.getParam("tagId");
helper.doRemove(component, parentId, tagId);
}
})
TagSelectHelper :
({
doRemove : function(component, parentId, tagId) {
console.log('helper'); // never displayed in console
var action = component.get("c.removeTag");
action.setParams({
parentId: parentId,
tagId: tagId
});
action.setCallback(this, function(a) {
var result = a.getReturnValue();
console.log(result);
if(result == null) {
var tags = component.get('v.tags');
var idx = 0;
for(var i = 0; i < tags.length; i++) {
if(tags[i].tagId == tagId && tags[i].tagRecordId == parentId) {
tags.splice(i, 1);
break;
}
}
component.set('v.tags', tags);
}
});
$A.enqueueAction(action); // never called, nothing happens, and no debug logs are generated
}
})
I can't find what I did wrong.
I tried to put the helper code into a $A.getCallback but no luck (maybe I've been mistaken in the syntax ?)
Does someone understand what's happening ?
Thank you very much !