You need to sign in to do that
Don't have an account?
Jaseem Pookandy 8
Lightning Components Basics Trailhead- passed the challenge, but app not working
My app is throwing an error in the callback method of createitem. Don't understand why... can someone pls take a look.. here is the code..
campingListController.js
CampingListController.apxc
CampingListHelper.js
Thanks,
campingListController.js
({ doInit : function(component,event,helper){ var action = component.get("c.getItems"); action.setCallback(this,function(response){ var state = response.getState(); console.log("state in init "+state); if(component.isValid() && state === "SUCCESS"){ component.set("v.items",response.getReturnValue()); }else{ console.log("Failed with state: " + state); } }); $A.enqueueAction(action); }, clickCreateCamping : function(component, event, helper) { if(helper.validateform(component)){ console.log("entered the block"); var newcamping = component.get("v.newItem"); helper.createItem(component,newcamping); } } })
CampingListController.apxc
public with sharing class CampingListController { @AuraEnabled public static list<Camping_Item__c> getItems(){ return([select id,name,packed__c,quantity__c,price__c from Camping_Item__c]); } @AuraEnabled public static Camping_Item__c saveItem(Camping_Item__c campitem){ system.debug('### this is called? '); insert campitem; return campitem; } }
CampingListHelper.js
({ createItem : function(component, camping){ var action = component.get("c.saveItem"); console.log("this is saveitem "+action); action.setParams({ "campitem":camping }); action.setCallback(this,function(response){ var state = response.getState(); console.log("what is state "+state); if(component.isValid() && state ==="SUCCESS"){ var items = component.get("v.items"); items.push(response.getReturnValue()); component.set("v.items",items); } }); $A.enqueueAction(action); }, validateform : function(component) { var validinput = true; var namefield = component.find("cliname"); var namevalue = namefield.get("v.value"); if($A.util.isUndefined(namevalue) ) { validinput = false; namefield.set("v.errors",[{message:"name cannot be null"}]); }else { namefield.set("v.errors",null); } console.log("validate "+validinput); return validinput; } })
Thanks,
Jaseem Pookandy 8
So after some play around I realized that passing JSON string to the apex method and then deserializing it works. But passing as an object still doesn't work...any idea??