0

I have a lightning component which fetches all the recordtypes of an object. The user kan select the desired recordtype from a picklist. How do I get the selected label or value in my controller. I tried below but this returns an empty label.

Component

Select a Record Type<br/>
                    <ui:inputSelect aura:id="selectid">
                        <aura:iteration items="{!v.lstOfRecordType}" var="rectype">                            
                            <ui:inputSelectOption text="{!rectype}" label="{!rectype}"/>
                        </aura:iteration>
                    </ui:inputSelect>
                <br/><br/>
                 <lightning:button class="slds-button slds-button-#brand" onclick="{!c.createRecord}">Next</lightning:button>

Controller

createRecord: function(component, event, helper) {
    component.set("v.isOpen", true);
    var recordTypeLabel = component.find("selectid").get("v.label");
        alert('recordTypeLabel: '+recordTypeLabel);            
  • you used same value ({!rectype}) for both label and text, so it gives same value, if you use different value for text then only we can get by index – sdandamud1 Jul 31 '19 at 14:18
1

It cannot get label as its not present in it. But you can get selected value by using:

var recordTypeLabel = component.find("selectid").get("v.value");

Note: you will get label when you define label on it. You can say

<ui:inputSelect label="Some Label" aura:id="selectid">

Then component.find("selectid").get("v.label") will return Some Label


Important: It is recommended to use lightning base components (like lightning:select or lightning:combobox) instead of ui base components.

  • I want to get the label of the selected input. In you rxample I dont get the selected input or am I missing something? I want to get: label="{!rectype}" – Thomas Jul 31 '19 at 10:50
  • Value (text) and label are same in select options. So use value. It's same as label – salesforce-sas Jul 31 '19 at 10:57

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.