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 disable-when-clicked controller when not in turbo

Oliver Günther14e5cd173875
diff --git a/app/views/account/_password_login_form.html.erb b/app/views/account/_password_login_form.html.erb
index 7dd30a45598..40cddc3f398 100644
--- a/app/views/account/_password_login_form.html.erb
+++ b/app/views/account/_password_login_form.html.erb
@@ -64,7 +64,10 @@ See COPYRIGHT and LICENSE files for more details.
<%= submit_tag t(:button_login),
name: :login,
class: "button -primary button_no-margin",
- data: { turbo_submits_with: t(:label_loading) } %>
+ data: {
+ controller: "disable-when-clicked",
+ "disable-when-clicked-text-value": t(:label_loading)
+ } %>
<div class="login-options-container">
<div class="login-links">
diff --git a/frontend/src/stimulus/controllers/disable-when-clicked.controller.ts b/frontend/src/stimulus/controllers/disable-when-clicked.controller.ts
new file mode 100644
index 00000000000..18c676e9b4e
--- /dev/null
+++ b/frontend/src/stimulus/controllers/disable-when-clicked.controller.ts
@@ -0,0 +1,29 @@
+import { Controller } from '@hotwired/stimulus';
+
+export default class DisableWhenClickedController extends Controller<HTMLInputElement> {
+ static values = {
+ text: String,
+ };
+
+ declare textValue:string;
+ private clickListener = this.toggleDisabled.bind(this);
+
+ connect() {
+ super.connect();
+ this.element.addEventListener('click', this.clickListener);
+ }
+
+ disconnect() {
+ this.element.removeEventListener('click', this.clickListener);
+ }
+
+ private toggleDisabled():void {
+ setTimeout(() => {
+ this.element.disabled = true;
+
+ if (this.textValue) {
+ this.element.textContent = this.textValue;
+ }
+ });
+ }
+}
diff --git a/frontend/src/stimulus/setup.ts b/frontend/src/stimulus/setup.ts
index 174b3260c37..eac911e6451 100644
--- a/frontend/src/stimulus/setup.ts
+++ b/frontend/src/stimulus/setup.ts
@@ -31,6 +31,7 @@ import { OpenProjectStimulusApplication } from 'core-stimulus/openproject-stimul
import { Application } from '@hotwired/stimulus';
import { BeforeunloadController } from './controllers/beforeunload.controller';
import ExternalLinksController from './controllers/external-links.controller';
+import DisableWhenClickedController from 'core-stimulus/controllers/disable-when-clicked.controller';
declare global {
interface Window {
@@ -41,6 +42,7 @@ declare global {
OpenProjectStimulusApplication.preregister('application', OpApplicationController);
OpenProjectStimulusApplication.preregister('async-dialog', AsyncDialogController);
OpenProjectStimulusApplication.preregister('disable-when-checked', OpDisableWhenCheckedController);
+OpenProjectStimulusApplication.preregister('disable-when-clicked', DisableWhenClickedController);
OpenProjectStimulusApplication.preregister('flash', FlashController);
OpenProjectStimulusApplication.preregister('menus--main', MainMenuController);
OpenProjectStimulusApplication.preregister('password-confirmation-dialog', PasswordConfirmationDialogController);