1
<lightning:inputfield aura:id="mailadd" fieldname="MailingAddress"/>

I'm trying to update it in controller: component.find('mailingadd').set('v.value',"what goes here?");

Component:

<lightning:recordEditForm aura:id="conRecordForm" objectApiName="Contact" onsubmit="{!c.contSubmitHandler}" onsuccess="{!c.redirecttoAccount}" onerror="{!c.conhandleErrors}" class="slds-hide" onload="{!c.updtConFields}">
                    <div class="slds-scrollable" style="height:25rem;width:auto">
                        <h3 class="slds-section-title--divider">Contact Information</h3>
                        <div class="slds-modal__content slds-p-around--medium slds-grid slds-wrap ">
                            <aura:iteration items="{!v.conFields}" var="conField">
                                <lightning:inputField aura:id="conflds" fieldName="{!conField}" class="slds-size--1-of-2 slds-p-horizontal_x-small"/>
                            </aura:iteration>  
                        </div>
                        <h3 class="slds-section-title--divider">Address Information</h3>
                        <div class="slds-modal__content slds-p-around--medium slds-grid slds-wrap ">
                            <lightning:inputField aura:id="mailingadd" fieldName="MailingAddress" class="slds-size--1-of-2 slds-p-horizontal_x-small"/>
                        </div>
                    </div>
                    <div class="slds-modal__footer">  
                        <lightning:button class="slds-m-top_small" label="Cancel" onclick="window.history.previous()"/>
                        <lightning:button class="slds-m-top_small" variant="brand" type="submit" label="Save" />
                    </div>
                </lightning:recordEditForm>

Please be informed that I can only access using component.find because I'm accessing this form from another form onsubmit action in the same page.

My intention is to mimic the auto population of Account field values on contact when new contact is clicked from the related section of an account(standard functionality). I was able to update all other fields from account, but MailingAddress is weird and won't update. Maybe, because it contains several fields in itself.

2 Answers 2

0

You use the component.find('mailadd').set('v.value', '<your value>') only when you want to control it programmatically. Example lets say you want to set this upon component load.

In this case, it will be the Address value in the format of address specific to the locale of the user. For example for USA it is Street address line 1, Street address line 2, City, State, ZipCode

If you want to save user provided values simply use it along with the lightning:recordEditForm

<aura:component>
    <div class="slds-p-around_medium">
        <lightning:recordEditForm objectApiName="Account"
                                     onsubmit="{!c.handleSubmit}">
            <lightning:messages />
            <lightning:inputField fieldName="MailingAddress" />
            <lightning:button type="submit" name="Submit" label="submit" class="slds-m-top_medium"/>
        </lightning:recordEditForm>
    </div>
</aura:component>
6
  • I was trying to populate address from account to contact, the problem is, mailingaddress has Mailingcountrycode,mailingpostalcode, etc in it, just like name has fn, ln, salutation...so I wanted to know how to set the value '<your value>'?
    – user61140
    Commented May 24, 2022 at 3:56
  • 1
    Set the value like example component.find('mailadd').set('v.value', '9700 Haven Port, Oltewah, TN, 37415>') should be fine . If it is variables concatenate them using + and commas. Commented May 24, 2022 at 4:23
  • I tried above, it doesn't seem to work, can't understand why...
    – user61140
    Commented May 24, 2022 at 7:09
  • Can you share more code with error description and behavior Commented May 24, 2022 at 7:21
  • I don't see any error, it doesn't reflect on the MailingAddress section. I think the format with which we're setting value is incorrect maybe. below is the statement I put debug. component.find('mailadd').get('v.value); Returns below: {"MailingCity":null,"MailingCountryCode":"US","MailingPostalCode":null,"MailingStateCode":null,"MailingStreet":null} then I tried this: component.find('mailadd').set('v.value',{"MailingCity":null,"MailingCountryCode":"US","MailingPostalCode":null,"MailingStateCode":null,"MailingStreet":'Test'}); Which isn't updating anything.
    – user61140
    Commented May 24, 2022 at 7:28
0

can you try something like this:

<aura:component>
    <div class="slds-p-around_medium">
        <lightning:recordEditForm objectApiName="Contact" onsubmit="{!c.handleSubmit}" aura:id="myRecordForm">
            <lightning:messages />
            <lightning:inputField fieldName="MailingAddress"  class="slds-hide"/>
            <lightning:button type="submit" name="Submit" label="submit" class="slds-m-top_medium"/>
        </lightning:recordEditForm>
    </div>
</aura:component>


handleSubmit: function(component,event,helper) {
    event.preventDefault();       // stop the form from submitting
    var fields = event.getParam('fields');
    **fields["MailingAddress"] = 'Your Mailing Address goes here';** 
    component.find('myRecordForm').submit(fields);
}
5
  • Yes, it's updating fields in the backend, but on UI we're unable to see the values populated.
    – user61140
    Commented May 24, 2022 at 10:46
  • because we added class="slds-hide" on MailingAddress filedName. can you remove the class and try?? Commented May 24, 2022 at 10:48
  • This form will be enabled by removing class slds-hide, so the issue is after the form is shown on the screen
    – user61140
    Commented May 24, 2022 at 11:15
  • what is the issue. could you share some screenshot to understand Commented May 24, 2022 at 11:20
  • In Mohith's answer, under comments I've shared the link of similar issue.
    – user61140
    Commented May 24, 2022 at 11:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .