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>
  • Is the problem the value, or is it a mismatch between value on the select and the selected on the option? – Drew Kennedy Aug 7 '19 at 16:47
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}"/>
| improve this answer | |

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.