Customization in Vue Predefined dialogs component

16 Mar 202312 minutes to read

You can customize the predefined dialogs buttons by using below properties.

  • okButton - Use this property to customize OK button text.
  • cancelButton - Use this property to customize Cancel button text.

Use the following code snippet for alert, confirm and prompt to customize the predefined dialogs action buttons.

For alert dialog , customized the default dialog button content as Dismiss by using the text property.

For confirm dialog, customized the default dialog buttons content as Yes and No by using the text property and also customized the dialog button icons by using icon property.

For prompt dialog , customized the default dialog buttons content as Connect and Close by using text property.

Alert action button

<template>
    <div class="predefinedDialog">
      <ejs-button id="alertDlgBtn" v-on:click.native="alertBtnClick" cssClass="e-danger">Alert</ejs-button>
    </div>
</template>

<style>
  @import "../../node_modules/@syncfusion/ej2-vue-popups/styles/material.css";
.predefinedDialog {
  height: 100%;
  min-height: 350px;
}
.e-dialog.customClass {
  min-width: 300px;
  min-height: 200px;
}
</style>

<script>
import Vue from "vue";
import { DialogUtility } from "@syncfusion/ej2-vue-popups";
import { ButtonPlugin } from "@syncfusion/ej2-vue-buttons";
Vue.use(ButtonPlugin);
Vue.use(DialogUtility);
export default {
  data: function () {
    return {};
  },
  methods: {
    alertBtnClick: function () {
      DialogUtility.alert({
        title: 'Good job!',
        content: 'You clicked the alert button!',
        width:'250px',
        okButton: { text: 'Done'}
      });
    },
  },
}
</script>

Confirm action buttons

<template>
  <div class="predefinedDialogs">
    <ejs-button id="confirmDlgBtn" v-on:click.native="confirmBtnClick" cssClass="e-success">Confirm</ejs-button>
  </div>
</template>

<style>
  @import "../../node_modules/@syncfusion/ej2-vue-popups/styles/material.css";
.predefinedDialogs {
  height: 100%;
  min-height: 350px;
}
</style>

<script>
import Vue from "vue";
import { DialogUtility } from "@syncfusion/ej2-vue-popups";
import { ButtonPlugin } from "@syncfusion/ej2-vue-buttons";
Vue.use(ButtonPlugin);
Vue.use(DialogUtility);
export default {
  data: function () {
    return {};
  },
  methods: {
    confirmBtnClick: function () {
      DialogUtility.confirm({
        title: 'Delete file',
        content: "Are you sure you want to permanently delete these file?",
        width: '300px',
        okButton: { text: 'Yes', icon:'e-icons e-check'},
        cancelButton: {text:'No', icon:'e-icons e-close'}
      });
    },
  },
}
</script>

Prompt action buttons

<template>
  <div class="predefinedDialogs">
      <ejs-button id="promptDlgBtn"  v-on:click.native="promptBtnClick" :isPrimary="true">Prompt</ejs-button>
  </div>
</template>

<style>
  @import "../../node_modules/@syncfusion/ej2-vue-popups/styles/material.css";
.predefinedDialogs {
  height: 100%;
  min-height: 350px;
}
</style>

<script>
import Vue from "vue";
import { DialogUtility } from "@syncfusion/ej2-vue-popups";
import { ButtonPlugin } from "@syncfusion/ej2-vue-buttons";
Vue.use(ButtonPlugin);
Vue.use(DialogUtility);
export default {
  data: function () {
    return {};
  },
  methods: {
     promptBtnClick: function () {
       DialogUtility.confirm({
        title: 'Join chat group',
        width: '300px',
        content: '<p>Enter your name: </p><input id= "inputEle" type="text" name="Required" class="e-input" placeholder="Type here.." />',
        okButton: { text: 'Connect'},
        cancelButton: {text:'Close'}
      });
    },
  },
}
</script>

Show or hide dialog close button

When rendering the predefined dialogs through utility methods, You can close the dialog using the following ways. The default values of closeOnEscape and showCloseIcon is false.

  • By pressing the escape key if the closeOnEscape property is enabled.
  • By clicking the close button if the showCloseIcon property is enabled.

You can also manually close the Dialogs by creating an instance to the dialog and call the hide method.

Use the following code for alert, confirm and prompt to demonstrates the different ways of hiding the utility dialog.

Alert dialog close button

<template>
  <div class="predefinedDialogs">
  <ejs-button id="alertDlgBtn" v-on:click.native="alertBtnClick" cssClass="e-danger">Alert</ejs-button>
  </div>
</template>

<style>
  @import "../../node_modules/@syncfusion/ej2-vue-popups/styles/material.css";
.predefinedDialogs {
  height: 100%;
  min-height: 350px;
}
</style>

<script>
import Vue from "vue";
import { DialogUtility } from "@syncfusion/ej2-vue-popups";
import { ButtonPlugin } from "@syncfusion/ej2-vue-buttons";
Vue.use(ButtonPlugin);
Vue.use(DialogUtility);
export default {
  data: function () {
    return {};
  },
  methods: {
    alertBtnClick: function () {
      DialogUtility.alert({
        title: "Low battery",
        content: "10% of battery remaining",
        width: "250px",
        showCloseIcon: true,
        closeOnEscape: true
      });
    },
  },
}
</script>

Confirm dialog close button

<template>
  <div class="predefinedDialogs">
    <ejs-button id="confirmDlgBtn" v-on:click.native="confirmBtnClick" cssClass="e-success">Confirm</ejs-button>
  </div>
</template>

<style>
  @import "../../node_modules/@syncfusion/ej2-vue-popups/styles/material.css";
.predefinedDialogs {
  height: 100%;
  min-height: 350px;
}
</style>

<script>
import Vue from "vue";
import { DialogUtility } from "@syncfusion/ej2-vue-popups";
import { ButtonPlugin } from "@syncfusion/ej2-vue-buttons";
Vue.use(ButtonPlugin);
Vue.use(DialogUtility);
export default {
  data: function () {
    return {};
  },
  methods: {
    confirmBtnClick: function () {
      DialogUtility.confirm({
        title: 'Delete file',
        content: "Are you sure you want to permanently delete these items?",
        width: '300px',
        showCloseIcon: true,
        closeOnEscape: true
      });
    },
  },
}
</script>

Prompt dialog close button

<template>
  <div class="predefinedDialogs">
    <ejs-button id="promptDlgBtn" v-on:click.native="promptBtnClick" :isPrimary="true">Prompt</ejs-button>
  </div>
</template>

<style>
  @import "../../node_modules/@syncfusion/ej2-vue-popups/styles/material.css";
.predefinedDialogs {
  height: 100%;
  min-height: 350px;
}
</style>

<script>
import Vue from "vue";
import { DialogUtility } from "@syncfusion/ej2-vue-popups";
import { ButtonPlugin } from "@syncfusion/ej2-vue-buttons";
Vue.use(ButtonPlugin);
Vue.use(DialogUtility);
export default {
  data: function () {
    return {};
  },
  methods: {
    promptBtnClick: function () {
      DialogUtility.confirm({
        title: "Join chat group",
        width: "300px",
        content:'<p>Enter your name: </p><input id= "inputEle" type="text" name="Required" class="e-input" placeholder="Type here.." />',
        showCloseIcon: true,
        closeOnEscape: true
      });
    },
  },
}
</script>

Customize dialog content

You can load custom content in predefined dialogs using the content property.

Use the following code to customize the dialog content to render the custom TextBox component inside the prompt dialog to get the username from the user.

<template>
  <div class="predefinedDialogs">
    <ejs-button id="confirmDlgBtn" v-on:click.native="confirmBtnClick" cssClass="e-success">Confirm </ejs-button>
  </div>
</template>

<style>
  @import "../../node_modules/@syncfusion/ej2-vue-popups/styles/material.css";
.predefinedDialogs {
  height: 100%;
  min-height: 350px;
}
</style>

<script>
import Vue from "vue";
import { DialogUtility } from "@syncfusion/ej2-vue-popups";
import { ButtonPlugin } from "@syncfusion/ej2-vue-buttons";
Vue.use(ButtonPlugin);
Vue.use(DialogUtility);
export default ( {
  data: function () {
    return {};
  },
  methods: {
    confirmBtnClick: function () {
      DialogUtility.confirm({
        title: "Join chat group",
        content: '<p>Enter your name: </p><input class="e-input"/>',
        width: "350px",
      });
    },
  },
});
</script>