From a4b48988fd418bdae5bc1cb56284f7ec2f7dcc5f Mon Sep 17 00:00:00 2001 From: Jane Sandberg Date: Fri, 13 Dec 2024 14:35:32 -0800 Subject: [PATCH] Add show.blacklight.blacklight-modal and ajax:success event listeners for when the form is submitted successfully in AJAX Find the show.blacklight.blacklight-modal in https://github.com/projectblacklight/blacklight/blob/main/app/javascript/blacklight-frontend/modal.js#L188 Co-authored-by: Jane Sandberg Co-authored-by: Christina Chortaria --- app/assets/javascripts/application.js | 8 ++++++++ app/views/catalog/_ask_a_question_form.html.erb | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 7fac5f9ac..bb70be089 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -23,3 +23,11 @@ // //= require ./custom_range_limit.js //= require ./orangelight.js + +// Wait for the modal to open +document.addEventListener('show.blacklight.blacklight-modal', function () { + // Wait for the form to be submitted successfully + $('.modal_form').on('ajax:success', function () { + Blacklight.Modal.hide(); + }); +}); diff --git a/app/views/catalog/_ask_a_question_form.html.erb b/app/views/catalog/_ask_a_question_form.html.erb index 5abc2e3c4..403b7cd61 100644 --- a/app/views/catalog/_ask_a_question_form.html.erb +++ b/app/views/catalog/_ask_a_question_form.html.erb @@ -1,6 +1,7 @@ <%= render :partial=>'shared/flash_msg' %> <%= simple_form_for( form, + remote: true, url: contact_question_path, data: { blacklight_modal: 'trigger' }, html: {class: "modal_form"} @@ -18,7 +19,7 @@ <%= f.input :feedback_desc, as: :hidden %> <% end %>