[SalesForce] How to override Save button and show the popup in lightning-record-form of LWC

I have the requirement to show a WARNING POPUP / confirmation box when user click on save button in Record form of Lightning Web Components(LWC).

Can i override save button and display confirm popup in Record form of LWC and based on user click on confirm or cancel i need to perform save or cancel.

If it is not possible with Record form, can i use combination of view and edit from to full fill my requirement. Or any way with Wire property or functionality.

Please help me with good approach and guide me please.

Thanks in advance. Any approaches are welcome.

Best Answer

Yes, You can do that. You need to handle onsubmit event in your record form:-

handleSubmit(event){
    event.preventDefault(); // it will prevent the submit
    const fields = event.detail.fields;
    if (window.confirm("Do you really want to save?")) { 
        this.template.querySelector('lightning-record-form').submit(fields); // it will submit the form
    }else{
    //do something
    }
}
Related Topic