You need to sign in to do that
Don't have an account?
vleandro
Action failed: c$campingList$controller$createCampingList
I've searched the forums high and low and I'm still not getting something right with this.
My form loads and loads my records from the database. The problem is when I try and go to "Create Camping Item" I get this error:
This page has an error. You might just need to refresh it. Action failed: c$campingList$controller$createCampingList [component is not defined] Failing descriptor: {c$campingList$controller$createCampingList}
Here's the code:
campingList.cmp
campingListController.js
campingListHelper.js
and last but not least, my Apex class, CampingListController.apxc
For the life of me I can't seem to figure out what is missing. Any and all help will be deeply appreciated. Thank you for your time!
My form loads and loads my records from the database. The problem is when I try and go to "Create Camping Item" I get this error:
This page has an error. You might just need to refresh it. Action failed: c$campingList$controller$createCampingList [component is not defined] Failing descriptor: {c$campingList$controller$createCampingList}
Here's the code:
campingList.cmp
<aura:component controller="CampingListController"> <aura:attribute name="items" type="Camping_Item__c[]"/> <aura:attribute name="newItem" type="Camping_Item__c" default="{'Name':'', 'Quantity__c':0, 'Price__c':0, 'Packed__c':false, 'sobjectType':'Camping_Item__c'}"/> <aura:handler name="init" action="{!c.doInit}" value="{!this}"/> <!-- NEW Campaing FORM --> <div class="slds-col slds-col--padded slds-p-top--large"> <!-- [[ Campaing form goes here ]] --> <div aria-labelledby="newCampaingForm"> <!-- BOXED AREA --> <fieldset class="slds-box slds-theme--default slds-container--small"> <legend id="newCampaingForm" class="slds-text-heading--small slds-p-vertical--medium"> Add Expense </legend> <!-- CREATE NEW Campaing FORM --> <form class="slds-form--stacked"> <div class="slds-form-element slds-is-required"> <div class="slds-form-element__control"> <ui:inputText aura:id="campingName" label="Camping Name" class="slds-input" labelClass="slds-form-element__label" value="{!v.newItem.Name}" required="true"/> </div> </div> <div class="slds-form-element slds-is-required"> <div class="slds-form-element__control"> <ui:inputNumber aura:id="quantity" label="Quantity" class="slds-input" labelClass="slds-form-element__label" value="{!v.newItem.Quantity__c}" required="true"/> </div> </div> <div class="slds-form-element"> <div class="slds-form-element__control"> <ui:inputCurrency aura:id="price" label="Price" class="slds-input" labelClass="slds-form-element__label" value="{!v.newItem.Price__c}"/> </div> </div> <div class="slds-form-element"> <ui:inputCheckbox aura:id="packed" label="Packed ?" class="slds-checkbox" labelClass="slds-form-element__label" value="{!v.newItem.Packed__c}"/> </div> <div class="slds-form-element"> <ui:button label="Create Camping Item" class="slds-button slds-button--brand" press="{!c.createCampingList}"/> </div> </form> <!-- / CREATE NEW EXPENSE FORM --> </fieldset> <!-- / BOXED AREA --> </div> <!-- / CREATE NEW EXPENSE --> </div> <!-- ITERATIING ITEM LISTS --> <div class="slds-card slds-p-top--medium"> <c:campingHeader /> <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> <!-- / ITERATIING ITEM LISTS --> </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()); } }); $A.enqueueAction(action); }, createCampingList : function(component, event, helper){ // If we pass error checking, do some real work if(helper.validateCampingForm(component)) { var newItem = component.get("v.newItem"); helper.createItem(component, newItem); } } })
campingListHelper.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()); } }); $A.enqueueAction(action); }, createCampingList : function(component, event, helper){ // If we pass error checking, do some real work if(helper.validateCampingForm(component)) { var newItem = component.get("v.newItem"); helper.createItem(component, newItem); } } })
and last but not least, my Apex class, CampingListController.apxc
public with sharing class CampingListController { @AuraEnabled public static List<Camping_Item__c> getItems() { String[] fieldsToCheck = new String[] { 'Id', 'Name', 'Quantity__c', 'Price__c', 'Packed__c', 'CreatedDate'}; Map<String, Schema.SObjectField> fieldDescribeTokens = Schema.SObjectType.Camping_Item__c.fields.getMap(); for(String field : fieldsToCheck) { if(! fieldDescribeTokens.get(field).getDescribe().isAccessible()){ throw new System.NoAccessException(); return null; } } //OK, they're cool, let 'em through return [SELECT Id, Name, Quantity__c, Price__c, Packed__c, CreatedDate FROM Camping_Item__c]; } @AuraEnabled public static Camping_Item__c saveItem(Camping_Item__c item) { upsert item; return item; } }
For the life of me I can't seem to figure out what is missing. Any and all help will be deeply appreciated. Thank you for your time!
Thank you.