0

I have a lookup component in lightning. The parent component code snippet

<th class="slds-align-bottom"><c:LookupCmp objectName="User"
                                      field_API_text="Name"
                                      field_API_val="Id"
                                      field_API_search="Name"
                                      lookupIcon="standard:product" 
                                      selItem="{!v.assignedto}" 
                                      placeholder="Enter Assigned To"
                            /></th> 
                            <!--Hidden Input Field used to pass the lookup value-->
                            <aura:if isTrue="{! not(empty(v.assignedto)) }"> 
                                <lightning:input aura:id = "assignedToInput" value ="{#v.assignedto.text}" /><br />
                            </aura:if>

Here the value "{#v.assignedto.text}" is correctly holding the text of lookup value selected within the lightning input. However I am unable to pass it to the jscontroller as I am not being able to tag it to any attribute. Is there any way to achieve this

  • have you tried component.find('aura:id').get('v.value') ? Working with Attribute Values in JavaScript – glls Mar 21 '18 at 19:36
  • This totally works and I was constantly trying with component.find('aura:id').value which was definitely not working. Please provide this as an answer. So, I can mark it as correct. @glls – Rimii Mar 21 '18 at 19:50
4

As documented in Working with Attribute Values in JavaScript

try using:

component.find('aura:id').get('v.value') 

Practical Example from the doc:

component.cmp

<aura:component>
    <aura:attribute name="buttonLabel" type="String"/>
    <lightning:button aura:id="button1" label="Button 1"/>
    {!v.buttonLabel}
    <lightning:button label="Get Label" onclick="{!c.getLabel}"/>
</aura:component>

component.js

({
    getLabel : function(component, event, helper) {
        var myLabel = component.find("button1").get("v.label");
        component.set("v.buttonLabel", myLabel);
    }
})

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.