• Andrew Howell 15
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi All,

I am facing issue with  Lightning:inputField with lightning:recordEditForm that when I am trying to programatically change the value of any field I am able to do only if user is not modifying that field manully on screen

What I mean is that, lets say I have a form using lightning:recordEditForm with only two fields of account which are Name and Type.
And I want a logic to introduce that, I want to add selected Type as Prefix on the Name field, I have created a on change method and doing it in that, and that is working as expected if user only changing the Type field
BUT if user first edit the Name field then select/change the Type its not.


Below is the my sample code
CustomRecordEditForm.cmp
<aura:component implements="flexipage:availableForAllPageTypes,forceCommunity:availableForAllPageTypes,force:lightningQuickAction,force:hasRecordId" access="global">
    <aura:attribute name="recordId" type="String"/>
    <div class="slds-container-outer">
        <div class="slds-container">
            <lightning:recordEditForm aura:id="recordViewForm" objectApiName="Account" recordId="{!v.recordId}">
                <lightning:messages />
                <lightning:inputField fieldName="Name" aura:id="Name" />
                <lightning:inputField fieldName="Type" aura:id="Type" onchange="{!c.handleTypeChange}"/>
            </lightning:recordEditForm>
        </div>
    </div>
</aura:component>

CustomRecordEditFormController.js
({
	handleTypeChange : function(component, event, helper) {
		var typeValue = component.find("Type").get("v.value");
        var nameValue = component.find("Name").get("v.value");
        if(typeValue != null && typeValue != '' && typeValue != undefined){
            if(nameValue.indexOf(":") > 0){
                nameValue = nameValue.split(':')[1];
            }
            component.find("Name").set("v.value",typeValue+":"+nameValue);
        }
	}
})

Thanks in Advance!