You need to sign in to do that
Don't have an account?
Jordan Vasquez
How to grab label/innerText from Lightning:select picklist?
Hey everyone,
I want to grab the value of my label for a dynamic picklist but I am not sure how it is to be done and I have scoured the Internet and have not found anything that works for myself. Right now I am using the value field to grab the ID of an Account from the picklist but I also need to grab the name. I figured I would be able to grab it from the selected option's label but I haven't been able to do it.
Here is the lightning:select in my new lightning component:
And here is my controller:
Thanks for any help!
I want to grab the value of my label for a dynamic picklist but I am not sure how it is to be done and I have scoured the Internet and have not found anything that works for myself. Right now I am using the value field to grab the ID of an Account from the picklist but I also need to grab the name. I figured I would be able to grab it from the selected option's label but I haven't been able to do it.
Here is the lightning:select in my new lightning component:
<lightning:select aura:id="accountSelect" name="account" label="Select Account" required="true" value="{!v.acctId}" onchange="{!c.changeAccount}"> <aura:iteration items="{!v.lstAccount}" var="acct" > <option value="{!acct.Id}" >{!acct.Name}</option> </aura:iteration> </lightning:select>
And here is my controller:
changeAccount: function(component,event,helper){ console.log('Account changed.'); var label = component.find("accountSelect").get("v.label"); console.log('log that it changed, new account name: ' + label); }
Thanks for any help!
You need to do a workaround to get Value and label both of a picklist
I hope this will help you
Regards
Ashif
All Answers
You need to do a workaround to get Value and label both of a picklist
I hope this will help you
Regards
Ashif
<ui:inputSelect value="{!v.selectedAccounts}" aura:id="levels" label="Activity" change="{!c.changeActivity}">
<ui:inputSelectOption text="None" label="None"/>
<aura:iteration items="{!v.acts}" var="level">
<ui:inputSelectOption text="{!level.FullInfo__c}" label="{!level.Name}"/>
</aura:iteration>
</ui:inputSelect>
I am trying to get the text value of the selected option, i am not able to get it. Can you please help on this?
I tried below, it gives me the value not the text
console.log(component.find("levels").get("v.value"));//for drop downlist Value
Am i missing something. Please help.. Thanks
Try this: