Skip to content

Commit

Permalink
Add compatibility with Django 4.1 formset added event
Browse files Browse the repository at this point in the history
In Django 4.1, the 'formset:added' event is a native JS event.
See django/django@eabc22f91
  • Loading branch information
claudep committed Jun 6, 2022
1 parent 608314a commit a28d68e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Changelog

This document describes changes between each past release.

- Support new non-jQuery formset:added event triggered on Django 4.1
- Confirmed support for Django 4.0
- Drop support for Django 3.0 and Python 3.6
- Add Python 3.10 support
Expand Down
20 changes: 13 additions & 7 deletions tinymce/static/django_tinymce/init_tinymce.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,24 @@
}
}

function initializeTinyMCE(element, formsetName) {
Array.from(element.querySelectorAll('.tinymce')).forEach(area => initTinyMCE(area));
}

ready(function() {
// initialize the TinyMCE editors on load
document.querySelectorAll('.tinymce').forEach(function(el) {
initTinyMCE(el);
});
initializeTinyMCE(document);

// initialize the TinyMCE editor after adding an inline in the django admin context.
if (typeof(django) !== 'undefined' && typeof(django.jQuery) !== 'undefined') {
django.jQuery(document).on('formset:added', function(event, $row, formsetName) {
$row.find('textarea.tinymce').each(function() {
initTinyMCE(this);
});
django.jQuery(document).on('formset:added', (event, $row, formsetName) => {
if (event.detail && event.detail.formsetName) {
// Django >= 4.1
initializeTinyMCE(event.target);
} else {
// Django < 4.1, use $row
initializeTinyMCE($row.get(0));
}
});
}
});
Expand Down

0 comments on commit a28d68e

Please sign in to comment.