1

I am attempting to fire the standard submit event from recordEditForm by clicking a hidden button from javascript but the below code is not working for me any thoughts? I already attempted to use the Document.getElementById() so that I could use the base .click() event but the lightning button cannot have id as an attribute.

Aura:

<lightning:inputField fieldName="Sales_District_Lookup__c" onchange="{!c.onRecordSubmit}" />
<lightning:button 
           aura:id="submit"
           type="submit" 
           label="Save"  />

Javascript:

onRecordSubmit: function (component, event, helper) 
{   
    component.find('submit').click();
},
  • 1
    How do you know it's not working? – sfdcfox Jan 2 at 21:36
  • @sfdcfox through the magic of testing and getting an error – Calvin OKeefe Jan 2 at 22:10
  • 2
    @CalvinOKeefe I would not have asked had your question included the error message. When asking, please try to include error messages and other relevant data. – sfdcfox Jan 2 at 22:16
  • @sfdcfox will do next time – Calvin OKeefe Jan 2 at 22:16
3

Your lightning:inputField would be inside lightning base component like lightning:recordEditForm, why not directly call the submit method from your js onRecordSubmit?

<lightning:recordEditForm recordId="003XXXXXXXXXXXXXXX" objectApiName="MyObject__c" aura:id="myForm" >

    <lightning:inputField fieldName="Sales_District_Lookup__c" onchange="{!c.onRecordSubmit}" />
    <lightning:button 
               aura:id="submit"
               type="submit" 
               label="Save"  />
</lightning:recordEditForm>

JS code:

onRecordSubmit: function (component, event, helper) 
{   
    component.find('myForm').submit();
},

Src: https://developer.salesforce.com/docs/component-library/bundle/lightning:recordEditForm/documentation

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.