RichardSoeteman.NET

Implementing a confirmation dialog in Umbraco 14

Published 15 May 2024

At the moment I am (finally) at the final stage of the conversion of MemberExport  to Umbraco 14. One of the things that needs to be done is removing an item from saved definitions. Of course  you want a confirmation from the user before deleting the item from the database and this is never been easier before. It took me 5 minutes to complete this task. This includes opening up the Umbraco source code and look how they have done this.

umbConfirmModal

If you search for a confirmation modal for Umbraco 14 you end up with this page but in fact it is much easier. When  looking at the source code I found that Umbraco was using the umbConfirmModal. This modal gives you a few options to set appearance, header ,content and the name of the confirm button. When you cancel the rest of the method will be ignored, otherwise the delete method is executed.

private async _removeMenuItem(id:string |undefined, name:string|null |undefined){
        await umbConfirmModal(this, {
            color: 'danger',
            headline: 'Remove "'+name +'"?',
            content: 'Are you sure you want to remove this export definition?',
            confirmLabel: 'Delete',
        });
        this.#memberExportDefinitionContext?.deleteExportDefinition(id)
    }
Result

The result is a nice consistent dialog. Now I only need to translate the hard-coded text in the source code what will be another 5 minutes. 

Dialog