0

...I have tried EVERYTHING and cant seem to find what I am doing wrong. I am trying to prepopulate ParentWorkOrder on a new workorder lightning record create here is my code. I am new to writing components so please help.

<aura:component access="global">

    <aura:attribute name="recordId" type="String"/>
    <aura:attribute name="parentId" type="String" default="0WO54000000D0zw"/>
    <aura:attribute name="ONOFF" type="string" default="false"/>

    <lightning:recordEditForm aura:id="recordEditForm"
                           recordId="{!v.recordId}"
                           objectApiName="WorkOrder"
                           onsubmit="{!c.handleOnSubmit}"
                           onsuccess="{!c.handleSuccess}">        
        <lightning:messages />
        <lightning:inputField fieldName="Service_Filters_Needed__c" />
        <lightning:inputField fieldName="Is_there_an_issue_with_equipment__c" />
        <lightning:outputField fieldName="ParentWorkOrder" aura:id="parentWOLookup" value=""/>
        <lightning:button class="slds-m-top_small" type="submit" label="submit" />
    </lightning:recordEditForm> 
</aura:component>

controller

({

    handleSuccess : function(component, event, helper) {
        var payload = event.getParams().response;
        console.log(payload.id);
        component.set("v.ONOFF", true);     
    },


    handleOnSubmit : function(component, event, helper) {
      var fields = event.getParam("fields");
      fields["ParentWorkOrder"] = component.get("v.parentId");
    }
})
  • 1
    Please give your questions a clear, descriptive title. "PLEASE HELP ME" in all caps does not help guide the relevant expertise to your question. – David Reed Feb 7 '19 at 21:16
  • it would be user error on my part, gotr it working now – Rebecca Ann Feb 7 '19 at 23:23
1

I haven't really tried it out, but based on what is mentioned in the documentation for lightning:recordEditForm:

If you capture the submit event and submit the form programmatically, use event.preventDefault() to cancel the default behavior of the event.

You will need to modify your handleOnSubmit JS function to something as below. You can refer more on the example as in the documentation on these behaviors.

handleOnSubmit : function(component, event, helper) {
    // add this in your function to stop submitting the form
    event.preventDefault(); 

    var fields = event.getParam("fields");

    // notice how ParentWorkOrder field is being referred
    fields.ParentWorkOrder = component.get("v.parentId"); 

    // submit the form now
    component.find('recordEditForm').submit(fields);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.