You need to sign in to do that
Don't have an account?
Trailhead Challenge: Refactor Components and Communicate with Events
I am getting error while saving the CampingList component :
Failed to save campingList.cmp: Invalid definition for null:CampingListController: null: Source
Here is my code .
Camping List.cmp
<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[]"/>
<!-- NEW EXPENSE FORM -->
<div class="slds-col slds-col--padded slds-p-top--large">
<c:campingListForm/>
</div>
<!-- / NEW EXPENSE 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="item">
<c:campingListItem item="{!item}"/>
</aura:iteration>
</div>
</section>
</div>
</aura:component>
CampingListController
({
// Load items from Salesforce
doInit: function(component, event, helper) {
// Create the action
var action = component.get("c.getItems");
// Add callback behavior for when response is received
action.setCallback(this, function(response) {
var state = response.getState();
if (component.isValid() && state == "SUCCESS") {
component.set("v.items", response.getReturnValue());
}
else {
console.log("Failed with state: " + state);
}
});
// Send action off to be executed
$A.enqueueAction(action);
},
handleAddItem : function (component,event,helper){
var action = component.get("c.saveItem");
var Item = event.getParam("item");
var lstItems = component.get("v.items");
lstItems.push(Item);
component.set("v.items",lstItems);
console.log("After:"+lstItems);
action.setParams({"CampingItem":Item});
action.setCallback(this,function(response){
var state = response.getState();
if (component.isValid() && state === "SUCCESS") {
//let the magic happen
}
});
$A.enqueueAction(action);
}
})
CampingListHelper
({
createCamping: function(component, item) {
var theitems = component.get("v.items");
var newitem = JSON.parse(JSON.stringify(item));
theitems.push(newitem);
component.set("v.items", theitems);
component.set("v.newItem",{ 'sobjectType': 'Camping_Item__c','Name': '','Quantity__c': 0,
'Price__c': 0,'Packed__c': false });
},
validateCampingItem: function(component) {
// Simplistic error checking
var validCamping = true;
// Name must not be blank
var nameField = component.find("campname");
if ($A.util.isEmpty(nameField.get("v.value"))){
validCamping = false;
nameField.set("v.errors", [{message:"Camping name can't be blank."}]);
} else {
nameField.set("v.errors", null);
}
if ($A.util.isEmpty(component.find("campQty").get("v.value"))){
validCamping = false;
component.find("campQty").set("v.errors", [{message:"Camping Quantity can't be blank."}]);
} else {
component.find("campQty").set("v.errors", null);
}
if ($A.util.isEmpty(component.find("campPrice").get("v.value"))){
validCamping = false;
component.find("campPrice").set("v.errors", [{message:"Camping Price can't be blank."}]);
} else {
component.find("campPrice").set("v.errors", null);
}
return(validCamping);
},
createItem: function(component, 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 items = component.get("v.items");
items.push(response.getReturnValue());
component.set("v.items", items);
}
});
$A.enqueueAction(action);
}
})
Can anyone help me on this ?
May I suggest you please check with below links from the community forums which might help you further with the above issue.
- https://developer.salesforce.com/forums/?id=906F0000000kDPpIAM
- https://salesforce.stackexchange.com/questions/175470/refactor-components-and-communicate-with-events
Hope this will help you pass the challenge.Kindly mark this as solved if it's resolved.
Thanks,
Nagendra
I tried it but no Luck.
Still same error .
This is solved; See my (Nirvik Mitter) answer here: https://developer.salesforce.com/forums/?id=906F0000000kDPpIAM
I cleared the Trailhead Challenge - Lightning Components Basics - All of them; This piece above (Connect Components with Events > Refactor Components and Communicate with Events) was the last difficult hurdle.
Hi Stalin,
Hope this solves your query. Have a look: https://developer.salesforce.com/forums/?id=906F0000000kDPpIAM
Kindly mark this as solved if it's resolved at your end too.
Hope this solves your query. Have a look at : https://github.com/anilvanjre/Connect-Components-with-Events
Just copy paste this code and check the challenge.
campingList.cmp:
campingListController.js : addItemEvent.evt :
campingListItem.cmp:
campingListItem.css: campingListForm.cmp: campingListFormContoller.js :
campingListFormHelper.js::
campingHeader.cmp:
campingApp.app:
Surya Pratap Singh 13
Your answer is working
Thanks