3

I have following code in component which is called by another lightning component from aura:iteration. I want to get value from lightning inputField when it is changed in the javascript controller and store in v.item.Rep_Name1__c. BTW Rep_Name1__c is a lookup field.How can we achieve it?

<aura:attribute name="item" type="OPS__c" default="{ 'sobjectType': 'OPS__c' } "/>
<lightning:recordEditForm aura:id="recordViewForm" 
                            recordTypeId="0121N000001TLGbQAO"
                            objectApiName="OPS__c">
    <lightning:inputField fieldName="Rep_Name1__c" value="{!v.item.Rep_Name1__c}" aura:id="testpp" onchange="{!c.getOppProcess}"/>
</lightning:recordEditForm>

Javascript Controller (I am getting undefined when I try to retrieve value)

({
getOppProcess: function(component, event, helper) {
    debugger;
    var test = component.find("testpp").get("v.value");
},
)}

Thanks in advance.

5
  • what have you tried so far in order to achieve this? have you encoutnered any problems while doing so? if so, please include any errors verbatim.
    – glls
    May 16 '18 at 18:47
  • i have updated my question. I am getting undefined when I try to retrieve inputfield value on change. May 16 '18 at 18:56
  • Is that a typo in your JS? You seem to find testpp whereas the id defined is testp
    – Jayant Das
    May 16 '18 at 19:05
  • typo mistake while writing question :) PS Edited question May 16 '18 at 19:07
  • You need to use "aura:id" instead of "id" in the inputfield.
    – Jayant Das
    May 16 '18 at 19:08
3

The issue is that you are using id attribute here:

<lightning:inputField id="testpp" fieldName="Rep_Name1__c" value="{!v.item.Rep_Name1__c}" onchange="{!c.getOppProcess}"/>

Whereas, you need to use aura:id here to be able to get the value in your JS:

<lightning:inputField aura:id="testpp" fieldName="Rep_Name1__c" value="{!v.item.Rep_Name1__c}" onchange="{!c.getOppProcess}"/>
2
  • it was just typo mistake while writing question. But i am not getting any value even if i use aura:id May 16 '18 at 19:14
  • 1
    I was able to get this running and was able to fetch the value in my JS with similar implementation. You may like to view if you are missing something in your code, because the one you posted here had typos, so something to look at.
    – Jayant Das
    May 16 '18 at 19:28
2

Found the answer. I was retrieving the value in a wrong way. The correct code is

getOppProcess: function(component, event, helper) {

    component.set("v.item.Rep_Name1__c", event.getParam('value'));
}

Thanks.

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.