Confirm Dialogs
Require user confirmation before executing destructive actions.
Basic Usage
Add #[Confirm] to any method to show a confirmation dialog before execution.
use LiVue\Attributes\Confirm;
#[Confirm('Are you sure you want to delete this item?')]
public function delete()
{
$this->item->delete();
$this->redirect('/items');
}
#[Confirm('Reset all settings to default?')]
public function resetSettings()
{
$this->settings = $this->defaults;
}
In Templates
Just call the method normally. The confirmation appears automatically.
<!-- The confirm dialog shows automatically -->
<button v-click:delete class="btn-danger">
Delete Item
</button>
<button @click="livue.call('resetSettings')">
Reset to Defaults
</button>
Inline Confirmation
For one-off confirmations, use livue.callWithConfirm() in the template.
<!-- Custom message per button -->
<button @click="livue.callWithConfirm('remove', [item.id], 'Remove this?')">
Remove
</button>
<!-- v-for with dynamic message -->
<div v-for="user in users">
{{ user.name }}
<button @click="livue.callWithConfirm('ban', [user.id], `Ban ${user.name}?`)">
Ban
</button>
</div>
Custom Confirm Handler
Replace the default browser confirm with a custom modal (SweetAlert2, etc.).
// Use SweetAlert2
LiVue.setConfirmHandler((message) => {
return Swal.fire({
title: 'Confirm',
text: message,
icon: 'warning',
showCancelButton: true,
confirmButtonText: 'Yes',
cancelButtonText: 'Cancel',
}).then((result) => result.isConfirmed);
});
// Or a simple custom modal
LiVue.setConfirmHandler((message) => {
return new Promise((resolve) => {
myModal.show(message, {
onConfirm: () => resolve(true),
onCancel: () => resolve(false),
});
});
});
Handler Requirements
Your custom handler must return a Promise that resolves to true (proceed) or false (cancel). The default handler uses window.confirm() which blocks synchronously.