diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ff6e69e9..f4fe7f73d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ All notable changes to `laravel-livewire-tables` will be documented in this file ## UNRELEASED - Fix Return Type hinting for Column Rendering to allow Enum columns +- Add Bulk Action Confirmations, using wire:confirm + - setBulkActionConfirms + - setBulkActionConfirmMessage + - setBulkActionConfirmMessages + - setBulkActionDefaultConfirmationMessage + - Localisation for confirmation message + ## [3.0.0-beta.4] - 2023-10-17 - Introduction of Loading Placeholder diff --git a/docs/bulk-actions/available-methods.md b/docs/bulk-actions/available-methods.md index 245e99a2b..41507dc24 100644 --- a/docs/bulk-actions/available-methods.md +++ b/docs/bulk-actions/available-methods.md @@ -133,3 +133,54 @@ public function configure(): void $this->setHideBulkActionsWhenEmptyDisabled(); } ``` + +## setBulkActionConfirms + +When a bulk action is included in the array passed to setBulkActionConfirms, the default wire:confirm pop-up will appear prior to executing the bulk action. The default message is: "Are you sure?". This should only be used if you wish to use the default message. + +```php +public function configure(): void +{ + $this->setBulkActionConfirms([ + 'delete', + 'reset' + ]); +} +``` +## setBulkActionDefaultConfirmationMessage + +You may use this method to over-ride the default message. To override the confirmation message for an individual Bulk Action, see the below setBulkActionConfirmMessage and setBulkActionConfirmMessages. You may also use the language files to do this. + +```php +public function configure(): void +{ + $this->setBulkActionDefaultConfirmationMessage('Are you certain?'); +} +``` + +## setBulkActionConfirmMessage + +You may use this method to specify a message other than the default message. + +```php +public function configure(): void +{ + $this->setBulkActionConfirmMessage('delete', 'Do you want to delete these items?'); +} +``` + +## setBulkActionConfirmMessages + +You may pass an array to this method, to more effectively update the confirmation message for a larger quantity of bulk actions. This expects an array keyed by the bulk action name, with the value being the message that will be displayed to the user. + +```php +public function configure(): void +{ + $this->setBulkActionConfirmMessages([ + 'delete' => 'Are you sure you want to delete these items?', + 'purge' => 'Are you sure you want to purge these items?', + 'reassign' => 'This will reassign selected items, are you sure?', + ]); +} +``` + diff --git a/resources/lang/en.json b/resources/lang/en.json index 0456f57e2..87b34925e 100644 --- a/resources/lang/en.json +++ b/resources/lang/en.json @@ -4,6 +4,7 @@ "Applied Filters": "Applied Filters", "Applied Sorting": "Applied Sorting", "Bulk Actions": "Bulk Actions", + "Bulk Actions Confirm": "Are you sure?", "Clear": "Clear", "Columns": "Columns", "Debugging Values": "Debugging Values", diff --git a/resources/views/components/tools/toolbar/bootstrap.blade.php b/resources/views/components/tools/toolbar/bootstrap.blade.php index 2cb4e0b98..ca8e516c8 100644 --- a/resources/views/components/tools/toolbar/bootstrap.blade.php +++ b/resources/views/components/tools/toolbar/bootstrap.blade.php @@ -220,6 +220,9 @@ hasConfirmationMessage($action)) + wire:confirm="{{ $component->getBulkActionConfirmMessage($action) }}" + @endif wire:key="{{ $tableName }}-bulk-action-{{ $action }}" @class([ 'dropdown-item' => $component->isBootstrap(), diff --git a/resources/views/components/tools/toolbar/tailwind.blade.php b/resources/views/components/tools/toolbar/tailwind.blade.php index 51a3e4ab0..7daa59c67 100644 --- a/resources/views/components/tools/toolbar/tailwind.blade.php +++ b/resources/views/components/tools/toolbar/tailwind.blade.php @@ -186,6 +186,9 @@ class="origin-top-right absolute right-0 mt-2 w-full md:w-48 rounded-md shadow-l @foreach ($component->getBulkActions() as $action => $title)