Closed EvelinaIo closed 3 months ago
A few insites here. This issue is caused by this particular line in Django^1:
row.find("*").each(function() {
updateElementIndex(this, options.prefix, totalForms.val());
});
and consequently by attempting to update the name^2 of the returned elements:
if (el.name) {
el.name = el.name.replace(id_regex, replacement);
}
The .find(...)
^3 jQuery function returns child elements across all depths, not just direct ones. As a result, it also returns the trix-editor
elements, which are custom elements implemented by TrixEditorElement
^4. Now, TrixEditorElement
does have indeed a name
attribute, which is explicitly set as a getter^5, so inlines.js
attempts to change it, which is not possible because TrixEditorElement
does not set a setter as well, for this property.
The way I suggest to approach this is go into the initializeEditors
function: https://github.com/withlogicco/django-prose/blob/a85149873d44dc62b7a0c4ce41adce07101bd3c6/prose/static/prose/editor.js#L49-L58
and define a setter property^6 for all trix-editor
elements that have the django-prose-editor
class.
Description
We are experiencing a TypeError in the console when attempting to add an item to a stacked inline in the Django admin. The issue occurs because the model for the inline contains a RichTextField.
Steps to Reproduce
Expected Behavior
A new inline form should be added without any errors.
Actual Behavior
A TypeError is thrown in the console, and the new inline form is not added.
Environment
OS: macOS 14.2 Django Version: 5.0.6 Django Unfold: 0.20.5 Django Prose: 2.0.0
Additional Context
The specific project uses Django unfold admin to override the theme. This issue appears to be related to the integration of the RichTextField within the stacked inline. The problem does not occur with inlines that do not contain a RichTextField.
It seems that the error occurs when the
inlines.js
script tries to update the name property fortrix-editor
, probably because it expects an input element, and fails because there is none.