function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Puneet_MishraPuneet_Mishra 

Handling Actions with Controllers Challenge

Hi All,

I was taking the 'Handling Actions with Controllers' challenge under Lightning Component Basic and got stuck and not sure where I am wrong.
Challenge was
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, updates the item value provider and disables the button.
I have created the component and was working on controller.js but always getting an error, below are my code
<aura:component >
    <aura:attribute name="item" type="Camping_Item__c" required="false"/>
    
    <p>Name:
        <ui:inputText value="{!v.item.Name}" />
    </p>
    
    <p>Price:
        <ui:inputCurrency value="{!v.item.Price__c}" />
    </p>
    
    <p>Quantity:
        <ui:inputNumber value="{!v.item.Quantity__c}" />
    </p>
    
    <p>Packed:
        <ui:inputCheckbox value="{!v.item.Packed__c}"/>
    </p>
    
    <ui:button label="Packed!" press="{!c.packItem}" />
    
</aura:component>
controller.js
({
	packItem : function(component, event, helper) {
		event.getSource().set('v.disabled', true);
        component.set("v.item.Packed__c", true);
    }
})
I have set required=false on campingListItem due to which I can add my component to my App without provided any value
campingListItemApp:
<aura:application >
	<c:campingListItem />
</aura:application>

but everytime I run my package I am getting an error :
User-added image

Can anyone explain why I am getting this error and if possible can provide me a solution.

Thank in Advance.

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

 
Daryn Aucoin 1Daryn Aucoin 1
Here is the most simplified version I could get working forboth the challenge and UI.  It does not create any variables to reference and is direct access.

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