0

In the lightning documentation it states that I should be able to set a default value with the <option value=""> inside of a lightning:select. When I attempt to do this, my option value gets overwritten with a value within the campaignOptions list. Why would I not be able to display this as the default value and require the user to update to a valid selection?

https://developer.salesforce.com/docs/component-library/bundle/lightning:select/documentation

<lightning:select aura:id="selectedCampaignId" name="selectedCampaignId" label="Select a Campaign:" required="true" value="{!v.selectedCampaignId}" onchange="{!c.isActive}" messageWhenValueMissing="Please select a Campaign">
    <!-- why is this being overwritten? -->
    <option value="">-- Please Select --</option> 
    <aura:iteration items="{!v.campaignOptions}" var="item">
        <option text="{!item.Name}" value="{!item.Id}" selected="{item.selected}"/>
    </aura:iteration>
</lightning:select>
1
  • Is the problem the value, or is it a mismatch between value on the select and the selected on the option? Aug 7, 2019 at 16:47

1 Answer 1

1

You are missing the data binding ! in selected:

<option text="{!item.Name}" value="{!item.Id}" selected="{item.selected}"/>

It should be:

<option text="{!item.Name}" value="{!item.Id}" selected="{!item.selected}"/>

You must log in to answer this question.

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