You need to sign in to do that
Don't have an account?
Raghu Ramanujam
lightning select : Display Selected Value after Save
Hi Gurus,
I followed the below link to create a Picklist field in the component.
https://naveendhanaraj.wordpress.com/2018/06/19/lightning-picklist-component/
It works fine, the selected value is saved correctly.. But I am not able to display the selected value. It shows the first value in list.
Can you please guide me ..
Thanks,
Raghu
This the below code from documentation.
<aura:component>
<aura:attribute name="options" type="List" />
<aura:attribute name="selectedValue" type="String" default="Red"/>
<aura:handler name="init" value="{!this}" action="{!c.loadOptions}" />
<lightning:select name="mySelect" label="Select a color:" aura:id="mySelect" value="{!v.selectedValue}">
<aura:iteration items="{!v.options}" var="item">
<option text="{!item.label}" value="{!item.value}" selected="{!item.selected}"/> </aura:iteration> </lightning:select> </aura:component>
In your client-side controller, define an array of options and assign this array to the items attribute.
({ loadOptions: function (component, event, helper) { var opts = [ { value: "Red", label: "Red" }, { value: "Green", label: "Green" }, { value: "Blue", label: "Blue" } ]; component.set("v.options", opts); } })
All Answers
Reference: https://developer.salesforce.com/docs/component-library/bundle/lightning:select/specification
I am using the below for lightning select, is this correct ?
<lightning:select aura:id="Select" value="{!v.prlist[0].CVP__c}" label="Test" onchange="{!c.handleCompanyOnChange}">
<aura:iteration items="{!v.picklistValues}" var="item" indexVar="key">
<option value="{!item.value}" selected="{!item.Selected==v.prlist[0].CVP__c}">
{!item}
</option>
</aura:iteration>
</lightning:select>
Thanks,
Raghu
Compare your code to the one in this project, it's extremely clear. Thanks to you, I just completed that project. :D
https://trailhead.salesforce.com/content/learn/projects/workshop-override-standard-action
This the below code from documentation.
<aura:component>
<aura:attribute name="options" type="List" />
<aura:attribute name="selectedValue" type="String" default="Red"/>
<aura:handler name="init" value="{!this}" action="{!c.loadOptions}" />
<lightning:select name="mySelect" label="Select a color:" aura:id="mySelect" value="{!v.selectedValue}">
<aura:iteration items="{!v.options}" var="item">
<option text="{!item.label}" value="{!item.value}" selected="{!item.selected}"/> </aura:iteration> </lightning:select> </aura:component>
In your client-side controller, define an array of options and assign this array to the items attribute.
({ loadOptions: function (component, event, helper) { var opts = [ { value: "Red", label: "Red" }, { value: "Green", label: "Green" }, { value: "Blue", label: "Blue" } ]; component.set("v.options", opts); } })