Read all the values from dialog on button click in EJ2 TypeScript Dialog control

8 May 20239 minutes to read

You can read the dialog element values by binding the action handler to the footer buttons. The buttons property provides the options to bind events to the action buttons. For detailed information about buttons, refer to the footer section. In the below sample, value of input elements within the dialog has been checked in the footer button click event and send the values as the content of confirmation dialog.

import { enableRipple } from '@syncfusion/ej2-base';
import { Button } from '@syncfusion/ej2-buttons';
import { Dialog } from '@syncfusion/ej2-popups';

let dialogObj: Dialog = new Dialog({
    header: 'User details',
    content: document.getElementById("dlgContent"),
    showCloseIcon: true,
    visible: false,
    buttons: [{
        buttonModel: { isPrimary: true, content: 'Submit' }, click:  function() {
    target: document.querySelector('body'),
    width: '400px',
    animationSettings: { effect: 'Zoom' },
    beforeOpen: onBeforeopen

document.getElementById('openBtn').onclick = (): void => {;

let modalObj: Dialog;

function createModalDialog() {
    if (!document.getElementById('modalDialog').classList.contains('e-dialog')) {
        modalObj = new Dialog({
            header: 'User details',
            content: getDynamicContent(),
            showCloseIcon: true,
            isModal: true,
            visible: true,
            width: '600px',
            buttons: [{buttonModel: {isPrimary: true, content: 'Yes'}, click:  function() {
            }}, {buttonModel: {isPrimary: false, content: 'No'}, click: function() {
            target: document.querySelector('body'),
            animationSettings: { effect: 'Zoom' }
    } else {
        modalObj.content = getDynamicContent();

function getDynamicContent(): string {
    let input: HTMLInputElement =  document.getElementById('dialog').querySelector('#name');
    let email: HTMLInputElement =  document.getElementById('dialog').querySelector('#email');
    let contact: HTMLInputElement =  document.getElementById('dialog').querySelector('#contact');
    let address: HTMLTextAreaElement =  document.getElementById('dialog').querySelector('#address');
    let template: string = "<div class='row'><div class='col-xs-6 col-sm-6 col-lg-6 col-md-6'><b>Confirm your details</b></div>" +
    "</div><div class='row'><div class='col-xs-6 col-sm-6 col-lg-6 col-md-6'><span id='name'> Name: </span>" +
    "</div><div class='col-xs-6 col-sm-6 col-lg-6 col-md-6'><span id='nameValue'>"+ input.value + "</span> </div></div>" +
    "<div class='row'><div class='col-xs-6 col-sm-6 col-lg-6 col-md-6'><span id='email'> Email: </span>" +
    "</div><div class='col-xs-6 col-sm-6 col-lg-6 col-md-6'><span id='emailValue'>" + email.value +
    "</span></div></div><div class='row'><div class='col-xs-6 col-sm-6 col-lg-6 col-md-6'>"+
    "<span id='Contact'> Contact number: </span></div><div class='col-xs-6 col-sm-6 col-lg-6 col-md-6'>"+
    "<span id='contactValue'>"+ contact.value +" </span></div></div><div class='row'><div class='col-xs-6 col-sm-6 col-lg-6 col-md-6'>"+
    "<span id='Address'> Address: </span> </div><div class='col-xs-6 col-sm-6 col-lg-6 col-md-6'><span id='AddressValue'>" + address.value +"</span></div></div>"
    return template;

function onBeforeopen(): void {
    document.getElementById('dlgContent').style.visibility = 'visible';
<!DOCTYPE html>
<html lang="en">

    <title>Essential JS 2 Dialog</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="" rel="stylesheet" />
    <link href="" rel="stylesheet" />
    <link href="" rel="stylesheet" />
    <link href="" rel="stylesheet" />
    <link href="" rel="stylesheet" />
    <script src=""></script>
    <script src="systemjs.config.js"></script>
<script src="" type ="text/javascript"></script>

    <div id='loader'>LOADING....</div>
    <div id='container'>
        <div id="target">
        <center><button id="openBtn" class="e-control e-btn">Open</button></center>
        <div id="dialog"></div>
        <div id="modalDialog"></div>
            <form id="dlgContent" style="visibility: hidden">
                <div class='form-group'>
                    <label for='name'>Name:</label>
                    <input type='name' value='' class='form-control' id='name'>
                <div class='form-group'>
                    <label for='email'>Email Id:</label>
                    <input type='email' value='' class='form-control' id='email'>
                <div class='form-group'>
                    <label for='contact'>Contact Number:</label>
                    <input type='contact' class='form-control' id='contact'>
                <div class='form-group'>
                    <label for='address'>Address:</label>
                    <textarea class='form-control' rows='5' id='address'></textarea>