function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
HYERI KIMHYERI KIM 

How to set default value in <lightning:select>

My code looks like this:

component
<lightning:select label="SalesUnit" variant="label-hidden" aura:id="SalesUnit__c" value="{!v.item.SalesUnit__c}" class="LIGHTNING_SELECT_SIZE">
                    <aura:iteration items="{!v.SalesUnit__c}" var="opt">
                        <option value="{!opt.text}" >{!opt.label}</option>
                    </aura:iteration>
                </lightning:select>

serverside
for(UOM__c uom : uomList){
            SelectOption so = new SelectOption(uom.UOM_UOM__c, uom.Id);
                 optionList.add(so);
        }


I want to change default value 'MT' to 'KG'. How can I do??
User-added image
 
Hemant_JainHemant_Jain
In the init method, you need to find the control in the component and set the value.
 
component.find("option").set("v.value", 'KG');


Below link can help you more on this.
https://salesforce.stackexchange.com/questions/154899/lightningselect-set-default-value-based-on-sobject-list-from-apex-controller
Suraj Tripathi 47Suraj Tripathi 47
Hi HYERI KIM,
Greetings!

In handler method (init), you have to set the component value.
component.find("NameOfComponent").set("v.value", "KG");

If you find your Solution then mark this as the best answer. 

Thank you!

Regards,
Suraj Tripathi