2

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>
     </div>
     <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}"/>
        </div>
    </div>

enter image description here

1
  • 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
    Commented Aug 8, 2017 at 6:55

1 Answer 1

3

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 = [];
componentList.forEach(function(each){
    componentLabels.push(each.get('v.label'));
});
console.log(componentLabels);
>>> ['Total Assets ($m)', 'Total Revenue ($m)']
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .