7

I'm going through the Salesforce Trailhead Module on Lightning Components and I'm on the section for Handling Events with Client Side Controllers. I'm copying the Component Event example and when saving the component that is supposed to be handling an event I get the following error.

Failed to save undefined: aura:handler has invalid name attribute value: trailheadMessage1: Source

This component is named "trailheadReceiver.cmp" and code is as follows

<aura:component >
    <aura:attribute name="myText" type="String" default="None" />    
    <aura:handler name="trailheadMessage1" action="{!c.answer1}" />

    <c:trailheadSender />
    Message: {!v.myText}
</aura:component>

My event component is named "trailheadMessage1.evt" and the code is as follows:

<aura:event type="COMPONENT" description="Event template" >
    <aura:attribute name="text1" type="String" />
</aura:event>

My component that is generating the event is named "trailheadSender.cmp" and the code is as follows:

<aura:component >    
    <aura:registerEvent name="trailheadMessage1" type="c:trailheadMessage1" />
    <ui:button label="1" press="{!c.send1}" />
    <ui:button label="2" press="{!c.send1}" />
</aura:component>

The name I'm using in my handler matches the name of the event component, as well as the name I've put in the tag. I've tried adding the event attribute to the tag, but I get an error saying that it can only have the name of event attributes, but not both. I've tried using the event attribute only, but then it complains that is only for APPLICATION events.

I can't figure out why I'm getting this error, or how to fix it.

2 Answers 2

5

Try changing:

<c:trailheadSender />

to

<c:trailheadSender trailheadMessage1="{!c.answer1}" />

and remove:

<aura:handler name="trailheadMessage1" action="{!c.answer1}" />
7
  • When I do that I get the following error "Failed to save undefined: A aura:handler that specifies an event="" attribute must handle an application event. Either change the aura:event to have type="APPLICATION" or alternately change the aura:handler to specify a name="" attribute.: Source" It seems using the event attribute is only mean for application level events.
    – dBeltowski
    Commented Aug 28, 2015 at 14:06
  • Updated the answer. You need to specify both the name and the event in the handler I think. Commented Aug 28, 2015 at 14:13
  • Sadly no luck, trying to add both the name and event attributes gives the following error: "Failed to save undefined: aura:handler must specify one and only one of name="…" or event="…": Source"
    – dBeltowski
    Commented Aug 28, 2015 at 14:15
  • Interesting - the Trailhead example shows both specified. Commented Aug 28, 2015 at 14:22
  • 1
    Marking your answer as correct. My last error was due to a typo in my component controller. Any chance you can explain what is happening?
    – dBeltowski
    Commented Aug 28, 2015 at 14:59
4

The Lightning Components module has been updated for Winter '16 in response to the Lightning Desktop launch. However, I believe you're still running a Summer '15 org. In receiver.cmp, you would have to replace the following lines:

<aura:handler name="messageEvent" event="c:theMessage" action="{!c.answer}"/>
<c:sender />

Replace those lines with:

<c:sender messageEvent="{!c.answer}"/>

This change corresponds to Component Event Bubbling in the Winter '16 release notes.

3
  • Indeed I am using a Summer '15 org, as I do not yet have access to a Winter '16 one.
    – dBeltowski
    Commented Aug 28, 2015 at 17:24
  • Can you tell me where is this <c:sender messageEvent="{!c.answer}"/> documented? I also run under same use case. My event is Component type and i am using <aura:handler event="c:theMessage" name = 'messageEvent' action="{!c.answer}"/> . I am using this based on trail head module.
    – Ankuli
    Commented Oct 9, 2015 at 13:27
  • @Ankuli, you'll need <c:sender messageEvent="{!c.answer}"/> only if you're still on a Summer '15 org. Trailhead has been updated for Winter '16 so that line of code is no longer there. Commented Oct 9, 2015 at 16:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .