-1

Hi have a requirement as follows:-

I want to make a Picklist value in the lightning component. After using the lightning:Select still i am not able to get the values provided in the list.

Codes as below:

List Created:----

<aura:attribute name="NoOfHoursStudy" type="String[]" default=" ,Less Then 1 hrs,in between 1 to 4hrs,
                                                                   In between 4 to 8 hrs,More then 8hrs"/>

Lightning select and values:---

<div class="slds-size_3-of-8">  
    <lightning:Select label="How many hours do you study ?" name="hrsstudy" value="{!v.NoOfHoursStudy}"> 
   <aura:iteration items="{!v.NoOfHoursStudy}" var="hrs"/>
   <option value="{!hrs}" text="{!hrs}"/>
      </lightning:Select>   
</div>
  • Not able to get the Picklist Values – Abhijeet Kumar Jan 20 at 3:17
2

Your default value is incorrect. It must be contained in [] (support for lists without [] is deprecated) and have appropriate ' characters.

<aura:attribute 
  name="NoOfHoursStudy" 
  type="String[]" 
  default="['','Less Then 1 hrs','in between 1 to 4hrs','In between 4 to 8 hrs','More then 8hrs']"/>

Also, your options attribute should be different than your selected value option, otherwise they'll get wiped out. Also, Lightning is case sensitive, so it should be lightning:select instead of lightning:Select.

<aura:attribute 
  name="NoOfHoursStudyOptions" 
  type="String[]" 
  default="['','Less Then 1 hrs','in between 1 to 4hrs','In between 4 to 8 hrs','More then 8hrs']"/>
<aura:attribute name="NoOfHoursStudy" type="String" />
<lightning:select 
  label="How many hours do you study ?" 
  name="hrsstudy" 
  value="{!v.NoOfHoursStudy}"> 
 <aura:iteration items="{!v.NoOfHoursStudyOptions}" var="hrs"/>
   <option value="{!hrs}" text="{!hrs}"/>
  </lightning:select>
0

Posting another answer if anyone facing similar issue. Problem is not in default value. You need to end your iteration(loop) after option not before. Check this code :

> <aura:attribute name="NoOfHoursStudy" type="String[]" default=" ,Less
> Then 1 hrs,in between 1 to 4hrs,
>                                                                In between 4 to 8 hrs,More then 8hrs"/> <div class="slds-size_3-of-8">  
>     <lightning:Select label="How many hours do you study ?" name="hrsstudy" value="{!v.NoOfHoursStudy}"> 
>         <aura:iteration items="{!v.NoOfHoursStudy}" var="hrs">
>         <option value="{!hrs}" text="{!hrs}"/>
>         </aura:iteration>
>     </lightning:Select>    </div>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.