最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Lightning Input field's value is undefined, even if it has value - Stack Overflow

programmeradmin3浏览0评论

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 = ponent.get("v.mailTo");
var toExtMail = ponent.get("v.mailExtTo");

Why is it ing undefined, even if I populate some value in the form?

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 = ponent.get("v.mailTo");
var toExtMail = ponent.get("v.mailExtTo");

Why is it ing undefined, even if I populate some value in the form?

Share edited Aug 22, 2020 at 4:15 Herohtar 5,6234 gold badges33 silver badges42 bronze badges asked Oct 18, 2019 at 19:26 Sakshi KSakshi K 271 gold badge2 silver badges5 bronze badges 1
  • maybe post the entire ponent. Do you have any <aura:attribute> tags for 'mailTo' and 'mailExtTo'? – KDH Commented Oct 19, 2019 at 22:56
Add a ment  | 

1 Answer 1

Reset to default 2

It's hard to know what the problem is without the entire ponent code. Do you have 'aura:attribute' tags for these fields? If you don't then I believe using ponent.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 = ponent.find("someId").get("v.value"); so you could try that out.

发布评论

评论列表(0)

  1. 暂无评论