Component :
<aura:if isTrue="{!v.internal}">
<lightning:layoutItem size="6" padding="horizontal-small">
<lightning:inputField fieldName="To__c" class = "customRequired" value = "{!v.mailTo}" required="true"/>
</lightning:layoutItem>
</aura:if>
<aura:if isTrue="{!v.external}">
<lightning:layoutItem size="6" padding="horizontal-small">
<lightning:inputField fieldName="ToExternal__c" class = "customRequired" value = "{!v.mailExtTo}" required="true"/>
</lightning:layoutItem>
</aura:if>
Helper :
var toMail = component.get("v.mailTo");
var toExtMail = component.get("v.mailExtTo");
Why is it coming undefined, even if I populate some value in the form?
It's hard to know what the problem is without the entire component code. Do you have 'aura:attribute' tags for these fields? If you don't then I believe using component.get("v.mailTo");
will not work as it is attempting to get an attribute that just doesn't exist. To get the value of the input field directly you could try adding the aura:id="someId"
attribute to the <lightning:inputfield/>
tags and then access them this way:
var toMail = component.find("someId").get("v.value");
so you could try that out.