Skip to content

Commit d1fea2f

Browse files
committed
Simplified code example
1 parent efc503a commit d1fea2f

File tree

1 file changed

+8
-19
lines changed
  • 14/umbraco-cms/customizing/extending-overview/extension-types/modals

1 file changed

+8
-19
lines changed

14/umbraco-cms/customizing/extending-overview/extension-types/modals/confirm-dialog.md

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ description: Ask the user for confirmation
44

55
# Confirm Dialog
66

7-
{% hint style="warning" %}
8-
This page is a work in progress and may undergo further revisions, updates, or amendments. The information contained herein is subject to change without notice.
9-
{% endhint %}
10-
117
This example shows how to open a confirm dialog. The `UMB_CONFIRM_MODAL` is a token that represents the confirm dialog. The `open` method takes the token and an object with the data for the confirm dialog. The `onSubmit` method returns a promise that resolves when the user confirms the dialog and rejects when the user cancels the dialog.
128

139
The confirm modal itself is built-in and does not need to be registered in the extension registry.
@@ -29,31 +25,24 @@ import { UMB_MODAL_MANAGER_CONTEXT, UMB_CONFIRM_MODAL } from '@umbraco-cms/backo
2925

3026
@customElement('my-element')
3127
export class MyElement extends UmbElementMixin(LitElement) {
32-
#modalManagerContext?: typeof UMB_MODAL_MANAGER_CONTEXT.TYPE;
3328

34-
constructor() {
35-
super();
36-
this.consumeContext(UMB_MODAL_MANAGER_CONTEXT, (instance) => {
37-
this.#modalManagerContext = instance;
38-
});
39-
}
4029

41-
#onRequestDisable() {
42-
const modalContext = this.#modalManagerContext?.open(
30+
async #onRequestDisable() {
31+
const context = await this.getContext(UMB_MODAL_MANAGER_CONTEXT)
32+
33+
const modal = context?.open(
4334
this, UMB_CONFIRM_MODAL,
4435
{
4536
data: {
46-
headline: `${this.localize.term("actions_disable")}`,
47-
content: `${this.localize.term(
48-
"defaultdialogs_confirmdisable"
49-
)}`,
37+
headline: `#actions_disable`,
38+
content: `#defaultdialogs_confirmdisable`,
5039
color: "danger",
5140
confirmLabel: "Disable",
5241
}
5342
}
5443
);
55-
modalContext
56-
?.onSubmit()
44+
45+
modal?.onSubmit()
5746
.then(() => {
5847
console.log("User has approved");
5948
})

0 commit comments

Comments
 (0)