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
Rose Marie FosterRose Marie Foster 

Challenge Not yet complete... here's what's wrong: The campingListItem JavaScript controller doesn't have a 'packItem' handler function."


I got this error "Challenge Not yet complete... here's what's wrong:
The campingListItem JavaScript controller doesn't have a 'packItem' handler function." when I check my code below:

Component: 

<aura:component >

    <aura:attribute name="item" type="Camping_Item__c" required="true"/> 
         
    <p>Name: 
        <ui:outputText value="{!v.item.Name}"/> 
    </p> 
    <p>Price: 
        <ui:outputCurrency value="{!v.item.Price__c}"/> 
    </p> 
    <p>Quantity: 
        <ui:outputNumber value="{!v.item.Quantity__c}"/> 
    </p> 
    <p>Packed: 
        <ui:outputCheckbox value="{!v.item.Packed__c}"/> 
    </p> 
 
     <ui:button label="Packed!" press="{!c.packItem}"/>
    
</aura:component>


CONTROLLER:

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


What did I miss? Sorry I am new to coding and still learning my way around it. If anyone could help me I would really appreciate it.
 
SandhyaSandhya (Salesforce Developers) 
Hi Rose Marie Foster ,

Below code worked for me.
 
<aura:component >
    <aura:attribute name="item" type="Camping_Item__c" required="true"/>
    
    
<aura:component implements="force:appHostable">
    <aura:attribute name="item" type="Camping_Item__c"/>
   <p><ui:outputText value="{!v.item}"/></p>
    <div>
        <ui:button label="Packed!"  press="{!c.packItem}"/>
    </div>
  </aura:component>

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

    }
})
Hope this helps you!

Please mark it as Best Answer if my reply was helpful. It will make it available for other as the proper solution.
 
Thanks and Regards
Sandhya