Concepts or coding lessons of Salesforce that you can implement easily

Modal/Popup Box In Lightning Component – Salesforce

How to implement Model or Popup Box in Lightning Component?

Use the below code to implement it. 

ModelDemo.cmp => Lightning Component Code

<aura:component>
    <!--use boolean attribute for Store true/false value,make default to "false" so modal box are not display on the load of component. --> 
    <aura:attribute name="isModelBoxOpen" type="boolean" default="false"/>
    
    <!--Use "slds-m-around_xx-large" class to add standard X-Large padding to the component--> 
    <div class="slds-m-around_xx-large">        
        <lightning:button variant="brand"
           label="What is Lightning Modal/PopUp Box?"
           title="What is Lightning Modal/PopUp Box?"
           onclick="{! c.openModel }" />
        <!--Use aura:if tag to display Model Box, on the bese of conditions. [isModelBoxOpenboolean attribute] -->   
        <aura:if isTrue="{!v.isModelBoxOpen}">            
            <!--###### MODAL BOX Start######--> 
            <section role="dialog" tabindex="-1" aria-labelledby="modal-heading-01" aria-modal="true" aria-describedby="modal-content-id-1" class="slds-modal slds-fade-in-open">
                <div class="slds-modal__container">
                    <!-- ###### MODAL BOX HEADER Start ######-->
                    <header class="slds-modal__header">
                        <lightning:buttonIcon iconName="utility:close"
onclick="{! c.closeModel }"
alternativeText="close"
variant="bare-inverse"
class="slds-modal__close"/>
                        <h2 id="modal-heading-01" class="slds-text-heading_medium slds-hyphenate">Lightning Modal/PopUp Box</h2>
                    </header>
                    <!--###### MODAL BOX BODY Part Start######-->
                    <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">
                        <p><b>Sit nulla est ex deserunt exercitation anim occaecat. Nostrud ullamco deserunt aute id consequat veniam incididunt duis in sint irure nisi. Mollit officia cillum Lorem ullamco minim nostrud elit officia tempor esse quis. Cillum sunt ad dolore quis aute consequat ipsum magna exercitation reprehenderit magna. Tempor cupidatat consequat elit dolor adipisicing asdasd asdetg jhkirty iouiodc eryrm, ksjlkdfjoern  oksmelsm ljsflr.
                            </b>
                        </p>
                    </div>
                    <!--###### MODAL BOX FOOTER Part Start ######-->
                    <footer class="slds-modal__footer">
                        <lightning:button variant="neutral" 
label="Cancel"
title="Cancel"
onclick="{! c.closeModel }"/>
                        <lightning:button variant="brand" 
label="Ok"
title="Ok"
onclick="{! c.submitBox }"/>
                    </footer>
                </div>
            </section>
            <div class="slds-backdrop slds-backdrop_open"></div>
            <!--###### MODAL BOX Part END Here ######-->            
        </aura:if>
    </div>
</aura:component>

ModelDemo.js => Lightning Js Controller Code

({
   openModel: function(component, event, helper) {
      // for Display Model,set the "isModelBoxOpen" attribute to "true"
      component.set("v.isModelBoxOpen", true);
   },
   closeModel: function(component, event, helper) {
      // for Hide/Close Model,set the "isModelBoxOpen" attribute to "False"  
      component.set("v.isModelBoxOpen", false);
   },
   submitBox: function(component, event, helper) {
      // set the "isModelBoxOpen" attribute to "False for close the model Box.
      component.set("v.isModelBoxOpen", false);
   },
})


ModelDemo.App => Lightning component App

<aura:application extends="force:slds">
    <c:ModelDemo/> <!-- here c: is org. namespace prefix-->
</aura:application>

Now Run ModelDemo.App and click on What is Lightning Modal/PopUp Box? button. :)

Subscribe blog for More updates !!! 


Read More: WhatsApp on Salesforce Integration in 5 Steps
                    Which Salesforce API Do I Use in Integration?
                    When To Use Salesforce REST API  
                   When To Use Salesforce SOAP API 
                   When To Use Salesforce Bulk API 

Latest Salesforce Interview Questions and Answers:

loading...

9 comments:

  1. I really enjoyed while reading your article and it is good to know the latest updates. Do post more. Please also read my topics about

    Salesforce Products
    Salesforce Consultant
    Salesforce Integration Service

    ReplyDelete
  2. Hi the information which is provided is amazing, thank you so much for such amazing information capital info solution also provides the best online sales force training and classroom training.

    ReplyDelete
  3. I mostly read your all post, you are doing a great job!!!!!

    Bulk Object Field Creator

    ReplyDelete
  4. I mostly read your post, you are doing a great job
    Please also read my post about

    Reach your Potential Customer by using Salesforce Marketing Cloud

    ReplyDelete
  5. Wonderful blog post, thank you so much for the great information which you provided.
    Top 5 features of salesforce lightning

    ReplyDelete
  6. Good Information Nitish Talekar, I am reading all your articles - Lexicon Infotech a Salesforce registered consulting and Implementaion partner

    ReplyDelete
  7. Nice Blog! you are doing a great job thanks for sharing your knowledge.....

    ReplyDelete
  8. Great Job my friend. I used this popup in my client's project.

    ReplyDelete
  9. Great Job my friend. I used this popup in one of my client's Org. Thanks again

    ReplyDelete