I am trying to get label value of ui:InputCurrency of Lightning Out component used in Visualforce page. I have three different input fields and I have given same aura:Id reason being I am doing some calculation with Switch statement in the controller. So I am trying to get the label value and use it in Switch case.

I tried component.find("totalvalue").label but it didn't work. What am I doing wrong here?

<aura:component description="ExecutiveSnapshot" controller="ExecSnapshotCalculations">
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:attribute name="ExecSS" type="Executive_Snapshot__c" default="{'sobjectType' : 'Executive_Snapshot__c'}"/>    
    <aura:attribute name="ParentAsset" type="String"/>

     <div class="slds-form-element">
        <div class="slds-form-element__control" >
            <ui:inputCurrency value="{!v.ExecSS.Total_Assets__c}" label="Total Assets ($m)" class="slds-input" labelClass="parentvalue" aura:Id="totalvalue" change="{!c.handleParentCalculation}"/>
     <div class="slds-form-element">
        <div class="slds-form-element__control" >
            <ui:inputCurrency value="{!v.ExecSS.Total_Revenue__c}" label="Total Revenue ($m)" class="slds-input" labelClass="parentvalue" aura:Id="totalvalue" change="{!c.handleParentCalculation}"/>

enter image description here

  • It should have been aura:id="totalvalue" instead of aura:Id="totalvalue". component.find("totalvalue") will return an array if two or more components have the same aura:id in a component.
    – Praveen
    Aug 8 '17 at 6:55

The syntax you're looking for is .get('v.label'); However, keep in mind that if there are multiple components with the same aura:id, you will get an array of components when you do component.find('totalvalue'). To get the labels you can loop through them like so:

var componentList = component.find('totalvalue');
var componentLabels = [];
>>> ['Total Assets ($m)', 'Total Revenue ($m)']

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.