You need to sign in to do that
Don't have an account?
John Lay 9
The campingListItem JavaScript controller isn't setting the 'Packed' value correctly.
Working the "Handle Actions with Controllers" trailhead module and I'm not getting past the validation.
If I put the component in a test jig, I can see the button function and set the check box as expected.
Here is the code I'm using to set the item as packed...
component.set("v.item.Packed__c", true );
I'm assuming the validator does not like my syntax. Can you give me a hint to get past this?
Thanks.
John
var a = component.get("v.item",true);
a.Packed__c = true;
component.set("v.item",a);
All Answers
var a = component.get("v.item",true);
a.Packed__c = true;
component.set("v.item",a);
I am trying to work on same trailhead challenge:
Add a button to the campingListItem component that when clicked, marks the item as packed.
- Add a button labeled "Packed!" that calls the packItem controller function when clicked.
- The controller action marks the item attribute as packed and disables the button.
However, am running into issue as: Cannot set property 'Packed__c' of null.Below is the code for reference:
Can you please correct me if am doing anything wrong.
Thanks.
Yashita
thank you for sharing!
Could you tell me where I can find more information about the "var a = component.get("v.item",true);" syntax? I don't get the need for a second argument?
By the way, is it possible to activate auto-completion in the developer console for ligthning development?
Best Regards
David
I hope you're fine. Have you managed to fix? I am facing the same issue "Cannot set property 'Packed__c' of null"
Thank you upfront for help
Best regards
Below is the code for reference
CampingListItem.cmp: CampingListItemController.js:
Thanks.
I've managed to fix. Just set the initial value to "Packed__C" in the component.
This is the part of code that I've used.
....
<aura:attribute name="item" type="Camping_Item__c"
default="{ 'sobjectType': 'Camping_Item__c',
'Packed__c': false}"/>
....
Bellow the controller code
....
packItem: function(component, event, helper) {
var a = component.get("v.item");
a.Packed__c = true;
component.set("v.item",a);
.....
Regards
JS Controller:
I'm really trying to understand what the heck I'm doing, verse just copy pasting the answers. I'm not sure why I'm getting my sob_item is undefined. any advise?
event.getSource() gives you your button. Then .get("v.item", true) tells the button to look within itself and find 'item' which doesn't exist.
'item' is actually found within 'component' so you need to do var sob_item = component.get("v.item", true);
Then the rest of that block of code should work and marks the item attribute as packed.
my 2cents
Less clear to me is why the "item" must be "getted" into a variable first. You would think that
component.set("v.item.Packed__c", true);
means the same thing; but it does not pass the "Check Challenge".
I did the challenge again and this worked for me (it also resolved the error I was getting in the earlier challenge with setting the required attribute to true.
I am little bit surprice about this excerise of trailhead. I am getting the following error message
This page has an error. You might just need to refresh it. Action failed: c:campingListItem$controller$packItem [Cannot set property 'Packed__c' of undefined] Failing descriptor: {c:campingListItem$controller$packItem}
Still my Excerise pass the validation.
here is my code
Component:
Controller:
I am getting error message
This page has an error. You might just need to refresh it. Action failed: c:campingListItem$controller$packItem [Cannot set property 'Packed__c' of undefined] Failing descriptor: {c:campingListItem$controller$packItem}
I check 100 time the field name , and it was correct.
apart from this my validation is successfully clear , but my code is still not working.