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

849 B
Raw Blame
import { StreamActions, StreamElement } from '@hotwired/turbo';

export function registerInputCaptionStreamAction() {
  StreamActions.addInputCaption = function addInputCaptionAction(this:StreamElement) {
    const target = document.querySelector(this.target);
    if (target) {
      const formControl = (target as HTMLElement).closest('.FormControl') as HTMLElement;

      if (this.getAttribute('clean_other_captions') === 'true') {
        formControl
          .querySelectorAll('.FormControl-caption')
          .forEach((caption) => caption.remove());
      }

      const caption = this.getAttribute('caption');
      if (caption && caption !== '') {
        const span = document.createElement('span');
        span.className = 'FormControl-caption';
        span.innerText = caption;
        formControl.append(span);
      }
    }
  };
}