+ Start a Discussion
Peter McGavinPeter McGavin 

The Name field is not being displayed using an expression.

Hi,
I am stuck on the Atttributes and Expressions challenge of the lightening component basics:

I get the following message: The Name field is not being displayed using an expression.

I'm really not 100% sure how the display component is meant to work for Name and Packed status - as there seems to be no "<lightening: /> formatting markup available. 

Here is my code:

<aura:component>

    <aura:attribute name="item" type="Camping_Item__c" required="true" />

    <aura:attribute name="expense" type="Expense__c"/>
    
    <p>Name: 
        <lightning:String value="{!v.item.Name__c}" style="Text"/>
    </p>
    
    <p>Price:
        <lightning:formattedNumber value="{!v.item.Price__c}" style="Currency"/>
    </p>
    
    <p>Quantity:
        <lightning:formattedNumber value="{!v.item.Quantity__c}" style="Number"/>
    </p>
    
    <p>Packed Status:
        <lightning:Checkbox value="{!v.item.Packed__c}" style="Toggle"/>
    </p>

</aura:component>

Thanks for your assistance in advance.
Best Answer chosen by Peter McGavin
Pasan   EeriyagamaPasan Eeriyagama
You could use lightning:formattedText component from here (https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/aura_compref_lightning_formattedText.htm). There is no lightning:String component.

Also I suggest you double check field "Name" it's may not be a custom one, but standard Name field. Hope it would help.

 

All Answers

Pasan   EeriyagamaPasan Eeriyagama
You could use lightning:formattedText component from here (https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/aura_compref_lightning_formattedText.htm). There is no lightning:String component.

Also I suggest you double check field "Name" it's may not be a custom one, but standard Name field. Hope it would help.

 
This was selected as the best answer
Peter McGavinPeter McGavin
Thanks but that did not work when I tried to save the .cmp 
I get the message: Failed to save campingListItem.cmp: The attribute "style" was not found on the COMPONENT markup://lightning:formattedText: Source
Pasan   EeriyagamaPasan Eeriyagama
It would be something like this.

<lightning:formattedText  value="{!v.item.Name}" />

You may want to look at this API Documentation reference https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/aura_compref_lightning_formattedText.htm (https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/aura_compref_lightning_formattedText.htm). Would be very useful. 
 
Peter McGavinPeter McGavin
Problem fixed. Thanks for your assistance. 
Sudhansu Bhusan DasSudhansu Bhusan Das
Here I am sharing The Successfully Executed code.Thanks pasan
<aura:component >
    <aura:attribute name="item" type="Camping_Item__c" required="true" />
      <p>Name:
        <lightning:formattedText  value="{!v.item.Name}" />
      </p>
      <p>Quantity:
        <lightning:formattedNumber value="{!v.item.Quantity__C}" style="Number"/>
      </p>
      <p>Price:
        <lightning:formattedNumber value="{!v.item.Price__c}" style="currency"/>
      </p>
      <p>
        <lightning:input type="toggle"                           
                         label="Packed"                          
                         name="Packed"                        
                         checked="{!v.item.Packed__c}" />
     </p>
</aura:component>
Filip Poverud 4Filip Poverud 4
<aura:component >
 
    <aura:attribute name="item" type="Camping_Item__c" required="True"/>
    
    <p>Name: {!v.item.Name}</p>
    <p>Price: {!v.item.Price__c}</p>
    <p>Quantity: {!v.item.Quantity__c}</p>
    <p>Packed: {!v.item.Packed__c}</p>
    
    <p>Price:
        <lightning:formattedNumber value="{!v.item.Price__c}" style="currency"/>
    </p>
    <p>Quantity:
        <lightning:formattedNumber value="{!v.item.Quantity__c}" style="number"/>
    </p>
    
    <p>
        <lightning:input type="toggle" 
                         label="Packed" 
                         name="packed" 
                         checked="{!v.item.Packed__c}"/>
    </p>
</aura:component>

As you are supposed to display values using three different ways, my code shows one section for each of the three ways of displaying the required data.