1

I am overriding related list object new button with a lightning component and trying to open it as a modal.

It is opening as a modal, but in a different tab. Can it open in the same record page, like how it opens for a standard page when we click new button in related list.

Can this modal logic be done in one single component rather than 2 component.

Component1 -

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    <aura:attribute name="recordId" type="String" />
    <c:LWC recordId="{!v.recordId}"/>
</aura:component>

Modal Component -

<aura:component implements="lightning:hasPageReference,lightning:actionOverride,force:hasRecordId,force:lightningQuickAction" access="global" >
    <lightning:overlayLibrary aura:id="overlayLib"/>
    <aura:handler name='init' action="{!c.init}" value="{!this}" />
    <aura:attribute name="recordId" type="Id"/>
</aura:component>

JS -

init : function(component, event, helper) {
    
    var modalBody;
    var modalFooter;
    $A.createComponents([
        ["c:Component1 ",{}]
    ],
                        function(components, status){
                            if (status === "SUCCESS") {
                                modalBody = components[0];
                                component.find('overlayLib').showCustomModal({
                                    header: "New Record",
                                    body: modalBody,
                                    showCloseButton: true,
                                    cssClass: "my-modal,my-custom-class,my-other-class",
                                    closeCallback: function() {
                                        
                                    }
                                });
                            }
                        }
                       );
}

1 Answer 1

0

You can have single component by below logic:

JS:

doInit: function(component, evt, helper) {
    component.find('overlayLib').showCustomModal({
        header: "Application Confirmation",
        body: component.find("modalContent"),
        showCloseButton: true,
        cssClass: "mymodal",
        closeCallback: function() {
            alert('You closed the alert!');
        }
    })
}

.cmp file:

<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<lightning:overlayLibrary aura:id="overlayLib"/>

<div class="slds-hide">
    <div aura:id="modalContent">
        This is modal content
    </div>
</div>

In the same way you can have Footer also in same component.

1
  • What about opening the component in the same page rather than the new one? Commented Mar 25, 2023 at 7:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .