I want to get the value from a lightning:inputField, but I can't.
Component:
<aura:attribute name="myAttribute" type="String"/>
{!v.myAttribute}
<lightning:recordEditForm objectApiName="Lead" onsubmit="{!c.submit}">
<lightning:inputField aura:id="myatt" fieldName="MyAtt__c" value="{!v.myAttribute}" label="Attribute"/>
</lightning:recordEditForm>
It seems like you can't set the value of an inputField? I've tried accessing this value both within the component using {!v.myAttribute}
, in the controller with component.get("v.myAttribute")
and with myAtt = component.find("myatt"); myVal = myAtt.get("v.value")
.
All are undefined.
Here is full code:
component:
<aura:component implements="force:hasRecordId,flexipage:availableForRecordHome">
<aura:attribute name="myAttribute" type="String"/>
{!v.myAttribute}
<lightning:recordEditForm objectApiName="Lead" onsubmit="{!c.submit}">
<lightning:inputField aura:id="myAtt" fieldName="Company" value="{!v.myAttribute}" label="Attribute" onchange="{!c.myChange}"/>
</lightning:recordEditForm>
Controller:
({
submit: function(component, event, helper){
console.log('hi');
},
myChange: function(component, event, helper){
console.log('hi');
var myEle = component.find("myAtt");
console.log(myEle);
var myAttri = component.find("myAtt").get("v.value");
console.log(myAttri);
}
})
Best Answer
Assuming your
lightning:inputField
tag has theaura:id
offirstNameField
, for example, you'd get its value with:In your second example, in your
find
call, you are using an uppercaseA
, whereas in your code theaura:id
has a lowercasea
:I've had some questions regarding the
recordEditForm
before too. This might be useful.Edit:
I think your attribute might also be conflicting. Would you mind commenting out your
myAttribute
attribute out of your code, and removing thevalue
attribute from the input field component?