1

Going the the lightning trailhead I'm at the challenge for camping list events. Everything is done in the CampingForm and all seems to work

In the form component

<aura:registerEvent name="addItem" type="c:addItemEvent"/>

the form controller validates and all works and calls this helper

createItem : function(component, citem) {
    var createEvent = component.getEvent("addItem");
    createEvent.setParams({"item":citem});
    createEvent.fire();
}

All seems to work fine Now in the campinglist component I need to handle that event When I add this and try to save it

<aura:handler name="addItem" type="c:addItemEvent" action="{!c.handleAddItem}" />

I get this error

'Failed to save undefined: aura:handler has invalid name attribute value: addItem'

Any ideas why it doesn't like this. I'm doing pretty much the exact same thing that works in the expense app so I am at a loss as to why I cannot save this.

5
  • There is a problem with the <aura:handler/> syntax, before that can you confirm whether c:addItemEvent is an Application or Component event?
    – Praveen
    Commented Aug 10, 2016 at 17:41
  • this is the definition of the addItemEvent <aura:event type="COMPONENT" > <aura:attribute name="item" type="Camping_Item__c" /> </aura:event> what is the problem with the <aura:handler syntax that you see?
    – Ohmicron
    Commented Aug 10, 2016 at 17:50
  • Can you change type to event: <aura:handler name="addItem" event="c:addItemEvent" action="{!c.handleAddItem}" /> Does that work?
    – Praveen
    Commented Aug 10, 2016 at 17:52
  • Try changing type="c:addItemEvent" to event="c:addItemEvent" - and remove the invalid 'name' attribute. Commented Aug 10, 2016 at 17:52
  • Thanks Caspar. I think that was it. Now I'm getting one of those totally generic errors. Error during init [TypeError: Cannot read property 'apply' of undefined] usually caused by a stupid typing syntax error but at least it is now letting me save the code with the handler tag.
    – Ohmicron
    Commented Aug 10, 2016 at 17:56

1 Answer 1

4

Since the addItemEvent is an COMPONENT event. You need to give the name,event and it action attribute.

Looking at your code, changing the type to event would solve the issue.

<aura:handler name="addItem" event="c:addItemEvent" action="{!c.handleAddItem}" />

You must log in to answer this question.

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