You need to sign in to do that
Don't have an account?

Error in trailhead challenge: The campingList component isn't handing the added item correctly.
Hi, Iam stuck in trailhead challenge in "Connect components with Events". I am getting above error(The campingList component isn't handing the added item correctly.), though my functionality is perfecly working fine. Please help me in this...I have tried solutions for the same error in this forum before, but they are not working as well.
CampingList.cmp:
CampingListController.js:
CampingList.cmp:
<aura:component controller="CampingListController"> <aura:handler name="init" action="{!c.doInit}" value="{!this}"/> <aura:handler name="addItem" action="{!c.handleAddItem}" event="c:addItemEvent"/> <aura:attribute name="items" type="Camping_Item__c[]" /> <c:campingHeader /> <c:campingListForm /> <aura:iteration items="{!v.items}" var="item"> <c:campingListItem item="{!item}" /> </aura:iteration> </aura:component>
CampingListController.js:
({ doInit: function(component, event, helper){ var action=component.get("c.getItems"); action.setCallback(this, function(response) { var state = response.getState(); if(component.isValid() && state=='SUCCESS') { component.set("v.items", response.getReturnValue()); } else { console.log("Error in state: "+ state); } }); $A.enqueueAction(action); }, handleAddItem : function(component, event, helper) { var item=event.getParam("item"); var action=component.get("c.saveItem"); action.setParams ({ "item" : item }); action.setCallback(this, function(response) { var state=response.getState(); if(component.isValid() && state == 'SUCCESS') { var itemArray=component.get("v.items"); itemArray.push(response.getReturnValue()); component.set("v.items", itemArray); } else { console.log('Error in state: '+ state); } }); $A.enqueueAction(action); }, })
Failed to save undefined: No EVENT named markup://c:addItemEvent found : [markup://c:campinglist]: Source
Heres my code:
<aura:component controller="CampingListController">
<aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
<aura:handler name="addItem" event="c:addItemEvent"
action="{!c.handleAddItem }"/>
<aura:attribute name="items" type="Camping_Item__c[]"/>
<ol>
<li>Bug Spray</li>
<li>Bear Repellant</li>
<li>Goat Food</li>
</ol>
<!-- NEW ITEM FORM -->
<div class="slds-col slds-col--padded slds-p-top--large">
<c:campingListForm />
</div>
<!-- / NEW ITEM FORM -->
<div class="slds-card slds-p-top--medium">
<header class="slds-card__header">
<h3 class="slds-text-heading--small">Items</h3>
</header>
<section class="slds-card__body">
<div id="list" class="row">
<aura:iteration items="{!v.items}" var="items">
<c:campingListItem item="{!item}"/>
</aura:iteration>
</div>
</section>
</div>
</aura:component>
The campingList component isn't handing the added item correctly.
I am able to save data, refresh on the page and clear the fields too.
campingList.cmp
campingListController.js
campingListHelper.js
campingListForm.cmp
campingListFormController.js
campingListFormHelper.js
addItemEvent.evt
Can some help me out in figuring what is it that I am missing?
Help appreciated
Lightning Component Framework Specialist
Challenge No #4
you will get help to clear this challenge.
https://developer.salesforce.com/forums/?id=9060G000000MUgLQAW
Regards,
Shashi Kumar
<aura:component controller="campingListController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
<aura:attribute name="newItem" type="Camping_Item__c" default="{ 'sobjectType': 'Camping_Item__c',
'Name': '',
'Price__c': 0,
'Quantity__c': 0,
'Packed__c': false
}"/>
<c:campingListForm />
<aura:handler name="AddItem" event="c:addItemEvent"
action="{!c.handleAddItem}"/>
<aura:registerEvent name="addItem" type="c:addItemEvent"/>
<lightning:layout >
<lightning:layoutItem padding="around-small" size="6">
<div aria-labelledby="newItemForm">
<!-- BOXED AREA -->
<fieldset class="slds-box slds-theme--default slds-container--small">
<legend id="newItemForm" class="slds-text-heading--small
slds-p-vertical--medium">
Add Camping Item
</legend>
<!-- CREATE NEW CAMPING ITEM FORM -->
<form class="slds-form--stacked">
<lightning:input type="text" aura:id="newItemForm" label="Name"
name="Name"
value="{!v.newItem.Name}"
required="true"/>
<lightning:input type="number" aura:id="newItemForm" label="Price"
name="Price"
min="0.1"
formatter="currency"
step="0.01"
value="{!v.newItem.Price__c}"
messageWhenRangeUnderflow="Enter an amount that's at least $0.10."/>
<lightning:input aura:id="newItemForm" label="Packed"
name="Packed" type="checkbox"
checked="{!v.newItem.Packed__C}" value="{!v.newItem.Packed__C}"
/>
<lightning:input type="number" aura:id="newItemForm" label="Quantity"
name="Quantity"
min="1"
step="1"
value="{!v.newItem.Quantity__c}"
placeholder="0"/>
</form>
</fieldset>
<!-- / BOXED AREA -->
</div>
<aura:iteration items="{!v.items}" var="item">
<c:campingListItem item="{!item}" />
</aura:iteration>
</lightning:layoutItem>
</lightning:layout>
</aura:component>