[SalesForce] How to set default value of inputselect in lightning

I have tried several methods already but this still wont work. It defaults to the first option in the list.

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/aura_compref_lightning_select.htm

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/aura_compref_ui_inputSelect.htm

currently, here's what I have

<ui:inputSelect class="slds-input slds-text-align-center" value="{! taskRec.status}">
    <aura:iteration items="{! v.status }" var="status" >
    <ui:inputSelectOption text="{! status }"/>
    </aura:iteration>
</ui:inputSelect>

taskRec.status – is being iterated as well. i displayed this in plain text and it returns the proper value
I just really need to set the same in the select option

Best Answer

From the documentation of the ui:inputSelectOption:

value : Boolean Indicates whether the status of the option is selected. Default value is “false”.

Then, you can use:

<ui:inputSelect class="slds-input slds-text-align-center">
    <aura:iteration items="{! v.status }" var="status" >
    <ui:inputSelectOption text="{! status }" value="{!status == taskRec.status}"/>
    </aura:iteration>
</ui:inputSelect>
Related Topic