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
Deepak Techmodel5Deepak Techmodel5 

Create a Packing List Item Component:attribute error and Quantity field formatted error ?

User-added image
campingListItem.cmp:

<aura:component implements="force:appHostable">
   <aura:attribute name="item" type="Camping_Item__c"/>
     <p>The Item is: 
         <ui:outputText value="{!v.item}" />
    </p> 
    <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>
    <p>
        <ui:button label="Packed!" press="{!c.packItem}"/>
    </p> 
</aura:component>

campingListController.js:

({
    packItem : function(component, event, helper) {
        
        var a = component.get("v.item");
    a.Name = 'Item2';
        a.Quantity__c = 20;
        a.Price__c = 200;
        a.Packed__c = true;
        component.set("v.item",a);
        
        var btnClicked = event.getSource();
        btnClicked.set("v.disabled",true);
        
    }
})
 
Niraj Kr SinghNiraj Kr Singh
Hi Deepak,
you can use this code snipet it will work for you:

<aura:component >
    <aura:attribute name="item" type="Camping_Item__c" required="false" />
    <p>Name:
        <ui:outputText aura:Id="name" value="{!v.item.Name}"/>
    </p>
    <p>Price:
        <lightning:formattedNumber aura:Id="pr" value="{!v.item.Price__c}" style="currency" />
    </p>
    <p>Quantity:
        <lightning:formattedNumber aura:id="qty" value="{!v.item.Quantity__c}"/>
    </p>
    <p>Packed?:
        <lightning:input type="toggle" label="Packed?" value="{!v.item.Packed__c}" />
    </p>
    <div>
        <lightning:button label="Packed!" onClick="{!c.packItem}"/>
    </div>
</aura:component>

Thanks
Niraj
Abhirup MukherjeeAbhirup Mukherjee
Hope this helps!!
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
<aura:attribute name="item"    type="Camping_Item__c" default=" , , " required="true"></aura:attribute>
<p>"{!v.item.Name}"</p>
    <p>Price:
        <lightning:formattedNumber value="{!v.item.Price__c}" style="currency"/>
    </p>
<p>Quantity:
    <lightning:formattedNumber value="{!v.item.Quantity__c}" style="currency"/>
    </p>
    <p>
        <lightning:input type="toggle" 
                         label="Packed"                           
                         name="Packed" 
                         checked="{!v.item.Packed__c}" />
     </p> 
    <p></p>
</aura:component>