I am trying to create a page so that I can create multiple sObject records in a single button click, with the help of lightning:recordEditForm component.
I checked the below link, and looks like this might work. Multiple lightning:recordEditForm
The issue is that before submitting the form, I want to edit the values for each of the record. So
- Is there any way to access the field values, update it and then submit?
- OR is there any way to send this data to an Apex Controller where I can edit records before saving?
This is how my code looks:
<aura:iteration items="{!v.data}" var="prod">
<lightning:recordEditForm aura:id="recordEditForm" objectApiName="OrderItem">
<div class="slds-grid slds-wrap">
<lightning:messages/>
<lightning:inputField fieldName="Quantity"/>
<lightning:inputField fieldName="PaymentTerms__c"/>
</div>
</lightning:recordEditForm>
</aura:iteration>
<lightning:button variant="brand" label="Next" onclick="{!c.handleSubmit}"/>
And this is the controller method:
handleSubmit: function (component, event, helper) {
const editForms = component.find('recordEditForm');
const forms = [].concat(editForms || []);
forms.forEach((form)=>{
// Retrieve the field values, update it
// ...
// ...
form.submit();
});
},
I checked this post below by Alba Rivas; she is manipulating the field values on submit controller method of lightning:recordEditForm. I just need this capability, but in my own defined controller method. https://albasfdc.com/2018/03/19/creating-pre-populated-records-with-lightningrecordeditform/