Customize the dialog appearance in EJ2 JavaScript Dialog control

8 May 20234 minutes to read

You can customize the dialog appearance by providing dialog template as string or HTML element to the content property. In the following sample, dialog is customized as error window appearance.

ej.base.enableRipple(true);

var dlgObj = new ej.popups.Dialog({
    header: 'File and Folder Rename',
    content: document.getElementById("dlgContent"),
    showCloseIcon: true,
    visible: false,
    buttons: [{
        buttonModel: { isPrimary: true, content: 'close' }, click:  function() { this.hide() }
    }],
    target: document.querySelector('body'),
    width: '400px',
    animationSettings: { effect: 'Zoom' },
    beforeOpen: onBeforeopen
});
dlgObj.appendTo('#dialog');

var button = new ej.buttons.Button({});
button.appendTo('#dialogButton');

document.getElementById('openBtn').onclick = function () {
    dlgObj.show();
};

function onBeforeopen() {
    document.getElementById('dlgContent').style.visibility = 'visible';
}
<!DOCTYPE html><html lang="en"><head>
    <title>Essential JS 2 Dialog customization</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="TypeScript UI Components">
    <meta name="author" content="Syncfusion">
    <link href="styles.css" rel="stylesheet">
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/25.1.35/ej2-base/styles/bootstrap.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/25.1.35/ej2-buttons/styles/bootstrap.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/25.1.35/ej2-inputs/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/25.1.35/ej2-popups/styles/bootstrap.css" rel="stylesheet">
    
    
<script src="https://cdn.syncfusion.com/ej2/25.1.35/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>
    
    <div id="container">
        <div id="target">
            <center><button id="openBtn" class="e-control e-btn">Open</button></center>
            <div id="dialog"></div>
            <div id="dlgContent" style="visibility: hidden" class="dialog-content">
                <div class="msg-wrapper  col-lg-12">
                    <span class="e-icons close-icon col-lg-2"></span>
                    <span class="error-msg col-lg-10">
                        Can not rename 'pictures' because a file or folder with that name already exists 
                    </span>
                </div>
                <div class="error-detail col-lg-8">
                    <span>Specify a different name</span>
                </div>
            </div>
        </div>
    </div>

<script>
var ele = document.getElementById('container');
if(ele) {
  ele.style.visibility = "visible";
}   
      </script>
<script src="index.js" type="text/javascript"></script>
</body></html>