From a18e8979391895b85b04356fe8bacd51ee9b5533 Mon Sep 17 00:00:00 2001 From: Eric Swierczek <2423727+swierczek@users.noreply.github.com> Date: Thu, 20 Feb 2025 13:55:22 -0600 Subject: [PATCH 1/2] Add must-interact documentation --- docs/development/services/modal.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/docs/development/services/modal.md b/docs/development/services/modal.md index 352682f28..3434761f7 100755 --- a/docs/development/services/modal.md +++ b/docs/development/services/modal.md @@ -130,6 +130,25 @@ Finally, we need to create our Bulk Action Controls with some special data attri Now when a user selects some content in the table, the bulk action controls should appear, and when "Remove" is selected and submitted, a modal will appear showing a list of content about to be deleted, where they can then confirm the deletion and your `POST` handler will be fired. +## Advanced functionality + +### Required interaction + +By default, clicking the close button, the escape key, or anywhere outside of the modal will close it, acting similar to cancelling the action the modal was prompting for. But if you want to prevent this default behavior and instead want to require the modal to be interacted with, you can add the `must-interact` class as part of the `name` parameter. + + $modal_vars = array( + 'name' => 'hello must-interact', + // ... other settings + ); + $modal_html = ee('View')->make('ee:_shared/modal_confirm_delete')->render($modal_vars); + +NOTE: Note: you will also need to add custom JS to remove `.must-interact`, and then trigger `$(modal).trigger('modal:close')` in order to close it. + + $('.modal-wrap .dialog__buttons button').on('click', function() { + $(this).closest('.must-interact').removeClass('must-interact'); + $(this).closest('.modal').trigger('modal:close'); + }); + ## CP/Modal Service Methods **class `ExpressionEngine\Service\Modal\ModalCollection`** From 1b8ac60a052e4aa30a7f3433b9d3cbb98b6423cd Mon Sep 17 00:00:00 2001 From: Eric Swierczek <2423727+swierczek@users.noreply.github.com> Date: Thu, 20 Feb 2025 13:57:43 -0600 Subject: [PATCH 2/2] Text update --- docs/development/services/modal.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/development/services/modal.md b/docs/development/services/modal.md index 3434761f7..ff63a5d47 100755 --- a/docs/development/services/modal.md +++ b/docs/development/services/modal.md @@ -142,7 +142,7 @@ By default, clicking the close button, the escape key, or anywhere outside of th ); $modal_html = ee('View')->make('ee:_shared/modal_confirm_delete')->render($modal_vars); -NOTE: Note: you will also need to add custom JS to remove `.must-interact`, and then trigger `$(modal).trigger('modal:close')` in order to close it. +NOTE: Note: you will also need to add custom JS to remove `.must-interact`, and then trigger the `modal:close` event in order to close it. $('.modal-wrap .dialog__buttons button').on('click', function() { $(this).closest('.must-interact').removeClass('must-interact');