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

658 B
Raw Blame
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;
      }
    });
  }
}