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
Jeff HansenJeff Hansen 

Handle Actions with Controllers

I'm going through this trail and I have gotten stuck on the Handle acitons with controllers module in the first section in the intermeidate developer trail. I am stuck onthe chalange for this module. The error i have not been able to get past is this: The campingListItem Lightning Component doesn't contain a button or its attributes are not set correctly when clicked.
I know the code i have now is not perfect, i have been messing with it trying everything i can think of for hours now. at this point this is what i have:
<aura:component >
    <aura:attribute name="item" type="Camping_Item__c" />
  
     <aura:attribute name="buttonDisabled" type="String" default="false"/>
   
    <ui:outputText value="{! v.item.name}"  />
     <ui:outputCheckbox value="{!v.item.Packed__c}"/>
     <ui:outputCurrency value="{!v.item.Price__c}"/>
     <ui:outputNumber value="{! v.item.Quantity__c}"  />
    <ui:button  label="Mark as packed" press="{!c.packItem}" disabled="{! v.buttonDisabled}" />
     
</aura:component>


and JS of
({
 packItem  : function(component, event, helper) {
      //component.set("v.item.Packed__c", true);      
       
       component.set("v.buttonDisabled", "true");         
 }
})


the one line is commented out because i was trying to just focus and get past this one error.
I just can't seem to figure out how the challenge want me to disable the button. very frustrating when the module doesn't give an example of how to do this and the challenge expects you to figure it out. I've looked at all the additional resources for the module and looked in forms and google, and i guess this is my last hope. otherwise I guess I'll have to skip this challenge...
Thanks for any help.
 
Hasmukh Jain 2Hasmukh Jain 2
I am also facing same issue. please provide solution
priyaSFDCpriyaSFDC
Hi Jeff,

The disabled attribute on the ui:button expects a boolean . So you might want to change either your attribute to a boolean type (Or) your code to <ui:button  label="Mark as packed" press="{!c.packItem}" disabled="{! v.buttonDisabled=='true'}" />

Please mark the answer if this resolved your issue.
Jeff HansenJeff Hansen
After a few more hours, i figured it out. partly my falut perhaps, I missed the part of Add a button labeled "Packed!". Then i got another error that could not get passed easily, but googled the error and it was the first link on these forms with the answer. So the complete challenge code is
<aura:component >
    <aura:attribute name="item" type="Camping_Item__c" />
    <ui:outputText value="{! v.item.name}"  />
     <ui:outputCheckbox value="{!v.item.Packed__c}"/>
     <ui:outputCurrency value="{!v.item.Price__c}"/>
     <ui:outputNumber value="{! v.item.Quantity__c}"  />
    <ui:button label="Packed!" press="{!c.packItem}"  /> 
</aura:component>
 and JS of
({
 packItem  : function(component, event, helper) {
        var a = component.get("v.item",true);
         a.Packed__c = true;
         component.set("v.item",a);
       
        var btnClicked = event.getSource();
        btnClicked.set("v.disabled", true);  
 }
})
Nathan HincheyNathan Hinchey
I found the same solution as @Jeff Hansen, but I'm curious about WHY. Why do we have to do
 
var a = component.get("v.item");
a.Packed__c = true;
component.set("v.item",a)

Instead of just doing
 
component.set("v.item.Packed__c",true)

?

What is the allowed syntax for v.attribute notation in controllers?