diff --git a/README.md b/README.md index 8aff6da..786f709 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,25 @@ public function actions(NovaRequest $request): array `exceptInline()` leaves actions available in Nova's bulk selector and detail view while removing them from the row ellipsis. +### Actions with form fields + +Actions that define fields use Nova's native action modal automatically. Leave +`confirm` unset so the action's own confirmation strategy, fields, validation, +file uploads, and dependent-field behavior are preserved. + +```php +RowActions::make('Actions') + ->add( + Reject::make(), + icon: 'x-mark', + color: 'danger', + ); +``` + +Do not set `confirm: false` on a field-bearing action unless it is intentionally +safe to execute with the fields' default values. That option maps directly to +Nova's `withoutConfirmation` behavior and bypasses the entire action modal. + ## Button options `add()` accepts the following named arguments: diff --git a/src/RowActions.php b/src/RowActions.php index 6763f67..a2b7e84 100644 --- a/src/RowActions.php +++ b/src/RowActions.php @@ -34,6 +34,7 @@ class RowActions extends Field * * Callbacks receive the row model, current Nova request, and action instance. * A null confirmation value preserves the action's native confirmation setting. + * A false value bypasses Nova's modal, including any fields defined by the action. * * @param Closure(Model, NovaRequest, Action): (Stringable|string|null)|Stringable|string|null $label * @param Closure(Model, NovaRequest, Action): (Stringable|string|null)|Stringable|string|null $tooltip diff --git a/tests/RowActionsTest.php b/tests/RowActionsTest.php index 341e976..8727c36 100644 --- a/tests/RowActionsTest.php +++ b/tests/RowActionsTest.php @@ -131,6 +131,30 @@ class RowActionsTest extends TestCase $this->assertFalse($actions[0]['action']['withoutConfirmation']); } + public function test_field_actions_preserve_novas_native_modal_strategy_by_default(): void + { + $field = RowActions::make() + ->add(ConfigurableAction::make()); + + $action = $this->serialize($field, $this->model())['actions'][0]['action']; + + $this->assertSame('confirm-action-modal', $action['component']); + $this->assertFalse($action['withoutConfirmation']); + $this->assertSame('reason', $action['fields'][0]['attribute']); + $this->assertSame('text-field', $action['fields'][0]['component']); + } + + public function test_confirm_false_explicitly_bypasses_the_native_action_modal(): void + { + $field = RowActions::make() + ->add(ConfigurableAction::make(), confirm: false); + + $action = $this->serialize($field, $this->model())['actions'][0]['action']; + + $this->assertNotEmpty($action['fields']); + $this->assertTrue($action['withoutConfirmation']); + } + /** @return array */ private function serialize(RowActions $field, RowActionModel $model): array {