I have created a lightning component with lightning record edit form and a couple of fields. Wrote a Javascript method such that When I change the first field to a particular value then second field is updated. Below is my code.
<aura:component implements="force:appHostable">
<aura:attribute name='test' type='String'/>
<lightning:recordEditForm
aura:id="editForm"
objectApiName="Case"
recordTypeId="{XXXXXXXXXXXXX}">
<div class="slds-col slds-size_1-of-2 slds-p-around_x-small">
<lightning:inputField aura:id="subject" fieldName="Subject" onchange="{!c.subjectChanged}"/>
</div>
<div class="slds-col slds-size_1-of-2 slds-p-around_x-small">
<lightning:inputField aura:id="description" value="{!v.test}" fieldName="Description"/>
</div>
</lightning:recordEditForm>
</aura:component>
Below is the Controller code
({
subjectChanged : function(component, event, helper) {
var subjectValue = component.find("subject").get("v.value");
if(subjectValue === "U") {
//var descriptionValue = component.find("description");
//descriptionValue.set("v.value","User");
component.set('v.test','User');
}
}
})
Whenever, user updates subject field to U, I want the description to be set to User. Any thoughts on this?
From documentation: https://developer.salesforce.com/docs/component-library/bundle/lightning:inputField/documentation
.....The assumption is that there are unsaved changes that should not be overwritten. If you want to be able to overwrite user changes, you can use lightning:input instead....