The ComponentContext instance exposes three methods that will open a dialog over the app to inform users about critical information, require them to make decisions or fill out a form.

There are three dialog variants available:

  1. Alert dialog
  2. Confirm dialog
  3. Form dialog

Alert dialog

Show an alert dialog with the specified title and message.

Options

PropertyTypeRequiredDefaultDescription
titlestringYes-Title of the dialog.
messagestringYes-Message to show on the dialog.
buttonTextstringNoDoneText to use on the action button.

Example

<template>
  <button @click="handleClick">Click me!</button>
</template>

<script>
export default {
  name: 'my-component',
  props: ['context'],
  methods: {
    handleClick() {
      this.context.openAlertDialog({
        title: 'Warning!',
      	message: 'Overflow valve is in open state.'
      });
    }
  }
};
</script>

<style scoped></style>
<script>
  export let context;
  
  function handleClick() {
    context.openAlertDialog({
      title: 'Warning!',
      message: 'Overflow valve is in open state.'
    });
  }
</script>

<button on:click={handleClick}>Click me!</button>

<style></style>

Confirm dialog

Show a confirmation dialog with the specified title and message. Optionally, an extra mandatory confirmation checkbox can be enabled. By indicating the confirmation result is destructive, the checkbox and confirm button will be styled in the warn theme palette.

Options

PropertyTypeRequiredDefaultDescription
titlestringYes-Title of the dialog.
messagestringYes-Message to show on the dialog.
cancelButtonTextstringNoCancelText to use on the cancelation action button.
confirmButtonTextstringNoConfirmText to use on the confirmation action button.
confirmCheckboxbooleanNofalseIndicates whether a confirm checkbox must be shown.
confirmCheckboxTextstringNoI am sureText to use for the confirm checkbox.
destructivebooleanNofalseIndicates that the confirmation result is destructive.

Example

<template>
  <button @click="handleClick">Click me!</button>
</template>

<script>
export default {
  name: 'my-component',
  props: ['context'],
  methods: {
    handleClick() {
      this.context.openConfirmDialog({
        title: 'Are you sure?',
        message: 'This action is not reversible!',
        confirmCheckbox: true,
        destructive: true
      }).then(confirmed => {
        if (confirmed) {
          // Do something destructive here.
        }
      });
    }
  }
};
</script>

<style scoped></style>
<script>
  export let context;
  
  function handleClick() {
    context.openConfirmDialog({
      title: 'Are you sure?',
      message: 'This action is not reversible!',
      confirmCheckbox: true,
      destructive: true
    }).then(confirmed => {
      if (confirmed) {
        // Do something destructive here.
      }
    });
  }
</script>

<button on:click={handleClick}>Click me!</button>

<style></style>

Form dialog

Show a form dialog.

Options

PropertyTypeRequiredDefaultDescription
titlestringYes-Title of the dialog.
messagestringNo-Message to show on the dialog.
cancelButtonTextstringNoCancelText to use on the cancelation action button.
submitButtonTextstringNoSubmitText to use on the submit action button.
discardChangesPromptbooleanNofalseIndicates whether a discard changes prompt is shown, when the form state is dirty and the user closes the form dialog by pressing escape, clicking on the backdrop or clicking on the cancel button.
inputsComponentInput[]Yes[]Inputs that will be rendered in the dialog content. These follow the same interface as the manifest component inputs.
initialValueobjectNo-Initial value for the form.

Example

<template>
  <button @click="handleClick">Click me!</button>
</template>

<script>
export default {
  name: 'my-component',
  props: ['context'],
  methods: {
    handleClick() {
      this.context.openFormDialog({
        title: 'Feedback',
        inputs: [
          {
            key: 'body',
            type: 'Text',
            label: 'Message',
            required: true,
            translate: false,
          },
        ],
        submitButtonText: 'Send feedback',
        discardChangesPrompt: true,
      }).then(result => {
        if (result) {
          console.log(result);
          // result: { value: { body: 'This is great!' } }
        }
      });
    }
  }
};
</script>

<style scoped></style>
<script>
  export let context;
  
  function handleClick() {
    context.openFormDialog({
      title: 'Feedback',
      inputs: [
        {
          key: 'body',
          type: 'Text',
          label: 'Message',
          required: true,
          translate: false,
        },
      ],
      submitButtonText: 'Send feedback',
      discardChangesPrompt: true,
    }).then(result => {
      if (result) {
        console.log(result);
        // result: { value: { body: 'This is great!' } }
      }
    });
  }
</script>

<button on:click={handleClick}>Click me!</button>

<style></style>