Skip to main content

CnDeleteDialog

Two-phase single-item delete confirmation dialog. Shows a warning, waits for API response, then shows success or error.

Try it

Loading CnDeleteDialog playground…

Wraps: NcDialog, NcButton, NcNoteCard, NcLoadingIcon

CnDeleteDialog confirmation dialog with warning text and Cancel/Delete buttons

CnDeleteDialog confirmation with warning text and Cancel/Delete buttons

Live demo

<template>
<div>
<button @click="open = true" style="padding: 6px 16px; border-radius: 4px; background: var(--color-primary-element); color: white; border: none; cursor: pointer;">Delete item</button>
<CnDeleteDialog
v-if="open"
ref="dlg"
:item="{ id: 1, title: 'Annual Report 2024' }"
@confirm="onConfirm"
@close="open = false" />
</div>
</template>
<script>
export default {
data() { return { open: false } },
methods: {
async onConfirm(id) {
await new Promise(r => setTimeout(r, 800))
this.$refs.dlg.setResult({ success: true })
},
},
}
</script>

Props

PropTypeDefaultDescription
itemObject(required)Item to delete (must have id)
nameFieldString'title'Field used as display name
nameFormatterFunctionnullOptional function (item) => string to format the display name. Overrides nameField when provided.
dialogTitleString'Delete Item'
warningTextString'Are you sure...'Supports \{name\} placeholder
successTextString'Item successfully deleted.'
cancelLabelStringCancel button label
closeLabelStringClose button label
confirmLabelStringConfirm button label

Events

EventPayloadDescription
confirmidDelete confirmed by user
closeDialog closed

Public Methods

MethodDescription
setResult(\{ success?, error? \})Set operation result after API call

Custom Name Formatting

When items don't have a simple name field, use nameFormatter to build a display name from any item properties:

<CnDeleteDialog
:item="auditTrail"
:name-formatter="(item) => t('myapp', 'Audit Trail #{id}', { id: item.id })"
@confirm="onDeleteConfirm"
@close="deleteItem = null" />

Two-Phase Pattern

<template>
<CnDeleteDialog
v-if="deleteItem"
ref="deleteDialog"
:item="deleteItem"
@confirm="onDeleteConfirm"
@close="deleteItem = null" />
</template>

<script>
export default {
methods: {
async onDeleteConfirm(id) {
try {
await api.delete(id)
this.$refs.deleteDialog.setResult({ success: true })
} catch (error) {
this.$refs.deleteDialog.setResult({ error: error.message })
}
},
},
}
</script>

Reference (auto-generated)

The tables below are generated from the SFC source via vue-docgen-cli. They reflect what's actually in CnDeleteDialog.vue and update automatically whenever the component changes.

Props

NameTypeRequiredDefaultDescription
itemobjectThe item to delete. Must have an id property.
nameFieldstring'title'Property name used for display (e.g., 'title', 'name')
nameFormatterfuncnullOptional function to format the item name. Receives the item, returns a string. Overrides nameField when provided.
dialogTitlestring() =&gt; t('nextcloud-vue', 'Delete item')Dialog title
warningTextstring() =&gt; t('nextcloud-vue', 'Are you sure you want to permanently delete "\{name\}"? This action cannot be undone.')Warning text. Use {name} as placeholder for the item name.
successTextstring() =&gt; t('nextcloud-vue', 'Item successfully deleted.')Success message
cancelLabelstring() =&gt; t('nextcloud-vue', 'Cancel')
closeLabelstring() =&gt; t('nextcloud-vue', 'Close')
confirmLabelstring() =&gt; t('nextcloud-vue', 'Delete')

Events

NamePayloadDescription
close
confirm

Methods

NameDescription
setResultSet the result of the delete operation. Call this from the parent after the API call completes.