Search results

Read all the values from dialog on button click

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.

Source
Preview
index.tsx
index.html
App.css.jsx
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import App  from './App';

ReactDOM.render(<App />, document.getElementById('container'));
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Syncfusion React Dialog</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Essential JS 2 for React 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="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-buttons/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-popups/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-inputs/styles/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='container'>
        <div id="dialog"></div>
        <div id="modalDialog"></div>
            <div id='loader'>Loading....</div>
        </div>
    </div>
</body>

</html>
import { DialogComponent } from '@syncfusion/ej2-react-popups';
import * as React from "react";
import './App.css';
class App extends React.Component {
    constructor() {
        super(...arguments);
        this.buttons = [{
                buttonModel: {
                    content: 'Submit',
                    cssClass: 'e-flat',
                    isPrimary: true,
                },
                'click': () => {
                    this.dlgbuttonClick();
                }
            }];
    }
    handleClick() {
        this.dialogInstance.show();
    }
    nestedbuttonClick() {
        this.innerDialogInstance.hide();
        this.dialogInstance.show();
    }
    footerbuttonclick() {
        this.innerDialogInstance.hide();
    }
    dialogContent() {
        return (<form>
        <div className='form-group'>
            <label>Name:</label>
            <input type='name' className='form-control' id='name' ref={n => this.nameInput = n}/>
        </div>
        <div className='form-group'>
            <label>Email Id:</label>
            <input type='email' placeholder='user@syncfusion.com' className='form-control' id='email' ref={e => this.emailInput = e}/>
        </div>
        <div className='form-group'>
            <label>Contact Number:</label>
            <input type='contact' className='form-control' id='contact' ref={c => this.contactInput = c}/>
        </div>
        <div className='form-group'><label>Address:</label>
            <textarea className='form-control' id='address' ref={a => this.addressInput = a}/>
        </div>
    </form>);
    }
    dlgbuttonClick() {
        this.dialogInstance.hide();
        this.innerDialogInstance.content = this.getDynamicContent();
        this.innerDialogInstance.buttons = [{ click: this.footerbuttonclick.bind(this), buttonModel: { content: 'Yes', isPrimary: true } },
            { click: this.nestedbuttonClick.bind(this), buttonModel: { content: 'No', isPrimary: true } }];
        this.innerDialogInstance.show();
    }
    getDynamicContent() {
        const template = "<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'>" + this.nameInput.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'>" + this.emailInput.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'>" + this.contactInput.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'>" + this.addressInput.value + "</span></div></div>";
        return template;
    }
    render() {
        return (<div className="App" id='dialog-target'>
      <button className='e-control e-btn' id='targetButton1' role='button' onClick={this.handleClick = this.handleClick.bind(this)}>Open</button>

      <DialogComponent id='dialog' width='400px' target='#dialog-target' header='Dialog' visible={false} closeOnEscape={false} showCloseIcon={true} buttons={this.buttons} ref={dialog => this.dialogInstance = dialog}>
        <div>{this.dialogContent()}</div>
      </DialogComponent>

      <DialogComponent id='innerDialog' header='User details' isModal={true} showCloseIcon={true} width='400px' visible={false} ref={dialog => this.innerDialogInstance = dialog} closeOnEscape={false} target='#dialog-target'/>
  </div>);
    }
}
export default App;