0

I have a picklist field on Account I have put some values in that field. I want to show this field in the lightning page but I don't have idea how to show this in the Lightning component.

find my code below:

 <aura:attribute name="newaccount" type="Account" 
               default="{'sobjectType': 'Account',
                  'Name': '',  
                  'Phone': '',
                  'Number_1st__c':'',
                  'Number_2nd__c':'',
                  'Total_No_addition__c':'',
                  'Choose_City__c':'',
                  'Account_create':''}"/>

Choose_City__c is a picklist

if I used below tag. It keeps on loading put screenshot.

<div class="slds-form-element">
        <force:inputField value="{!v.newaccount.Choose_City__c}"/>
</div>

enter image description here

if I use

<div class="slds-form-element">
   <lightning:input aura:id="city" type="String" label="Select City" 
                                 value="{!v.newaccount.Choose_City__c}"/>

It is showing as text field.

1
  • <lightning:input doesntt have picklist support as of now. force:inputField gets stuck in loading stage if you have not spelled the field name properly. May 2, 2018 at 11:36

1 Answer 1

2

There are 2 ways to do it.

  1. Do it using lightning:select where you describe set of options. https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/aura_compref_lightning_select.htm

    <aura:component>
    <lightning:select name="selectItem" label="Select an item" onchange="{!c.doSomething}">
        <option value="">choose one...</option>
        <option value="1">one</option>
        <option value="2">two</option>
    </lightning:select>
    </aura:component>
    
  2. A better option will be to use <force:inputField> It will automatically determine the type and show checkbox, picklist or text field.

    <aura:application extends="force:slds">
     <aura:attribute name="account" type="Account" 
               default="{ 'sobjectType': 'Account' }"/>
    
    Account Name: <force:inputField value="{!v.account.Name}"/><br></br>
    Ratings:  <force:inputField value="{!v.account.Risk_Rating__c}"/><!-- My picklist Field-->
    
    </aura:application>
    

    enter image description here https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/aura_compref_force_inputField.htm

3
  • It is showing as input text field
    – SFDC 44
    May 2, 2018 at 10:30
  • 2
    Added my tested code and screenshot. If you are still facing issue can you edit the main question and add the code you tried, we would then be able to help you debug. May 2, 2018 at 10:36
  • Updated my question and code. Please find
    – SFDC 44
    May 2, 2018 at 11:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .