• Emanuele Vacca
  • NEWBIE
  • 5 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
The controller action marks the item attribute as packed, updates the item value provider and disables the button is the task given in Trail head.

I have written the below controller to perform the action:

({
    packItem : function(component, event, helper) {
        event.getSource().set('v.disabled',true);
        component.set('v.item.Packed__c',true);
    }
})

This is setting the Packed__c to true but I am not passing the challenge.

but when I googled, below code was suggested:

({
    packItem : function(component, event, helper) {
        event.getSource().set('v.disabled',true);
        var a = component.get("v.item",true);
         a.Packed__c = true;
         component.set("v.item",a);
    }
})

But this code is not setting Packed__c to true. Please let me know the difference between two controller.

Trail head challenge:
https://trailhead.salesforce.com/lex_dev_lc_basics/lex_dev_lc_basics_controllers
HI ,I am doing a trailhead on salesforce Lighting this is my code 

<aura:component >
    <aura:attribute name="item"  type="Camping_Item__c"  /> <!-- required="true" type="String"  -->
    <p> The Item is <ui:outputText value ="{!v.item}"></ui:outputText></p>
    <p>Name:
        <ui:outputText value="{!v.item.name}" /> 
    </p>

    <p>Quantity:
        <ui:outputNumber value="{!v.item.Quantity__c}" /> 
    </p>

    <p>Price:
        <ui:outputCurrency value="{!v.item.Price__c}" /> 
    </p>

    <p>Packed?:
        <ui:outputCheckbox value="{!v.item.Packed__c}" /> 
    </p>
    
    <p><ui:button label="Packed!" press="{!c.packItem}"></ui:button>
    </p>
</aura:component>



Now Its required of me to :
Add a button to the campingListItem component that when clicked, marks the item as packed.
1.Add a button labeled "Packed!" that calls the packItem controller function when clicked.
2.The controller action marks the item attribute as packed and disables the button.

I have done with the first point
I'm struggling with the second point.

the controller code looks something like this (which currently isnt working)

({
    packItem : function(component, event, helper) {
        var btn= event.getSource();
        var BtnMessage =btn.get("v.label");  
        component.set("v.item","Packed");          
        btn.disabled=false;
    }
})



each time I have failing the trailhead because of this error message
Challenge Not yet complete... here's what's wrong: 
The campingListItem JavaScript controller isn't setting the 'Packed' value correctly.