0

I have used the lightning:recordEditForm. On click of the save button, the onsubmit function is not called.

If the submit function is called on the button onclick, then the record gets saved, but the onsuccess function is not called.

Component:

    <lightning:recordEditForm aura:id="recordEditForm" 
        recordId="!v.selectedConfigId}" 
        objectApiName="Priority_Points_Settings__c"
        onsubmit="{!c.onEditRecordSubmit}"
        onsuccess="{!c.onRecordSuccess}">
        <lightning:messages />

        <div class="slds-col slds-size_1-of-2">
            <!-- lightning:inputField components here -->
        </div>                              
    </lightning:recordEditForm>
<lightning:button variant="brand" label="Save" type="submit"/>

Controller:

onEditRecordSubmit : function(component, event, helper) {
        event.preventDefault();
        component.find('recordEditForm').submit();
    },


onRecordSuccess : function(component, event, helper) {
        console.log('>>In success');
    }
2

Your issue here is because of the lightning:button being outside of lightning:recordEditForm.

You will need to place the button within the form so that the button is wired with the form and its handler functions onsubmit and onsuccess.

Your component should look like this:

<lightning:recordEditForm aura:id="recordEditForm" 
    recordId="!v.selectedConfigId}" 
    objectApiName="Priority_Points_Settings__c"
    onsubmit="{!c.onEditRecordSubmit}"
    onsuccess="{!c.onRecordSuccess}">
    <lightning:messages />

    <div class="slds-col slds-size_1-of-2">
        <!-- lightning:inputField components here -->
    </div>                              

    <!-- button has been moved within the form -->
    <lightning:button variant="brand" label="Save" type="submit"/>    
</lightning:recordEditForm>
| improve this answer | |
  • Tried above changes.. But still facing same problem. – Ajinkyasd Jan 4 '19 at 14:42
  • You may like to refresh the cache. I was able to reproduce the issue and fix it with the approach as mentioned. The button always needs to be within the form for this to work. – Jayant Das Jan 4 '19 at 14:56
  • @Ajinkyasd Apart from the answer, event.preventDefault(); on your function onEditRecordSubmit() is blocking the action. – Raul Jan 4 '19 at 14:58
  • @Raul even with event.preventDefault(), the button being within the form works fine. I was able to get it working only when button was moved within the form. – Jayant Das Jan 4 '19 at 15:01
  • oh, when I added prevent default to my existing working component, submit handler was not saving the record. so thought that maybe the second problem. – Raul Jan 4 '19 at 15:03
0

I am not sure by this time you have found the solution for your issue or not. but for future reference'rs if any, might find helpful hence providing the solution.

In Your code the fields variable is missing . You are directly calling the form with form id but not providing the form fields values for submit function.

Try This:

onEditRecordSubmit : function(component, event, helper) {
event.preventDefault();
var fields = event.getParam("fields");
component.find('recordEditForm').submit(fields);
    }
| improve this answer | |

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.