Opened 5 years ago

Closed 3 years ago

#9596 closed defect (fixed)

dynamically adding textareas causes multiple toolbars for existing textareas

Reported by: wasserman Owned by: jun66j5
Priority: normal Component: TracWysiwygPlugin
Severity: normal Keywords:
Cc: Trac Release: 0.12


I have a use case where new textarea form fields can be added dynamically via JavaScript. The current logic adds new TracWysiwyg instances with corresponding toolbars to all textareas via TracWysiwyg.initialize. When a new textarea is created this causes each existing textarea to get an additional toolbar. This can be avoided by creating a property in each textarea and associating it to its TracWysiwyg instance after it is created. Here is suggested patch:

  • tracwysiwyg/htdocs/wysiwyg.js

     Index: tracwysiwyg/htdocs/wysiwyg.js
    40054005    var textareas = document.getElementsByTagName("textarea");
    40064006    for (var i = 0; i < textareas.length; i++) {
    40074007        var textarea = textareas[i];
    4008         if (/\bwikitext\b/.test(textarea.className || "")) {
    4009             TracWysiwyg.newInstance(textarea, options);
     4008        if (/\bwikitext\b/.test(textarea.className || "")
     4009            && !textarea.wysiwyg) {
     4010            textarea.wysiwyg = TracWysiwyg.newInstance(textarea, options);
    40104011        }
    40114012    }

Attachments (0)

Change History (2)

comment:1 Changed 5 years ago by wasserman

  • Summary changed from dynamically adding textareas causes multiple toolbars to existing textareas to dynamically adding textareas causes multiple toolbars for existing textareas

comment:2 Changed 3 years ago by jun66j5

  • Resolution set to fixed
  • Status changed from new to closed

In 13453:

TracWysiwygPlugin: marks initialized on data-tracwysiwyg-initialized attribute of textarea to prevent double-initializing (fixed #9596)

Add Comment

Modify Ticket

as closed The owner will remain jun66j5.
The resolution will be deleted. Next status will be 'reopened'.

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.