Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Add a `keepOpenOnSubmit` attribute to the dialog and remove duplicate code

Klaus Zandersdccbdcaefb61
diff --git a/app/views/shares/dialog.turbo_stream.erb b/app/views/shares/dialog.turbo_stream.erb
index a9fb2332c8b..8d44b236e46 100644
--- a/app/views/shares/dialog.turbo_stream.erb
+++ b/app/views/shares/dialog.turbo_stream.erb
@@ -1,6 +1,7 @@
<%= turbo_stream.dialog do
render(Primer::Alpha::Dialog.new(title: t(:label_share_project_list),
id: 'share_list',
+ data: { 'keep-open-on-submit': true },
size: :xlarge)) do |d|
d.with_header(variant: :large)
d.with_body do
diff --git a/frontend/src/turbo/setup.ts b/frontend/src/turbo/setup.ts
index 0f10dd45405..9a3f5d27a87 100644
--- a/frontend/src/turbo/setup.ts
+++ b/frontend/src/turbo/setup.ts
@@ -18,15 +18,3 @@ document.addEventListener('turbo:frame-missing', (event:CustomEvent) => {
event.preventDefault();
visit(response.url);
});
-
-// Close the primer dialog when the form inside has been submitted with a success response
-// It is necessary to close the primer dialog using the `close()` method, otherwise
-// it will leave an overflow:hidden attribute on the body, which prevents scrolling on the page.
-document.addEventListener('turbo:submit-end', (event:CustomEvent) => {
- const { detail: { success }, target } = event as { detail:{ success:boolean }, target:EventTarget };
-
- if (success && target instanceof HTMLFormElement) {
- const dialog = target.closest('modal-dialog') as ModalDialogElement;
- dialog && dialog.close(true);
- }
-});
diff --git a/frontend/src/turbo/turbo-event-listeners.ts b/frontend/src/turbo/turbo-event-listeners.ts
index 23a76c58a1c..3ef186bc28e 100644
--- a/frontend/src/turbo/turbo-event-listeners.ts
+++ b/frontend/src/turbo/turbo-event-listeners.ts
@@ -1,5 +1,9 @@
export function addTurboEventListeners() {
- // Close the primer dialog when the form inside has been submitted with a success response
+ // Close the primer dialog when the form inside has been submitted with a success response.
+ //
+ // If you want to keep the dialog open even after a successful form submission, you can add the
+ // `data-keep-open-on-submit="true"` attribute to the dialog element.
+ //
// It is necessary to close the primer dialog using the `close()` method, otherwise
// it will leave an overflow:hidden attribute on the body, which prevents scrolling on the page.
document.addEventListener('turbo:submit-end', (event:CustomEvent) => {
@@ -7,7 +11,7 @@ export function addTurboEventListeners() {
if (success && target instanceof HTMLFormElement) {
const dialog = target.closest('dialog') as HTMLDialogElement;
- dialog && dialog.close();
+ dialog && dialog.dataset.keepOpenOnSubmit !== 'true' && dialog.close();
}
});
}