-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow the input element name to be updated #381
Conversation
Useful when using formset's in Django. Will attempt to find the element set by the name but if it does not exist, set's the element id to the default Django id format.
I'm not familiar with Django. Can you explain the problem with before and after HTML examples? Also, would creating your own input element help? Trix will only create its own if you don't point it to an existing input element like: <trix-editor input="my_input"></trix-editor>
<input type="hidden" id="my_input"> |
Hi @javan , Thanks for taking the time to take a look at my PR! So the template form would look something like this:
When you request a new form, Django copies this template form and goes through each field on the form-row. As it does, it sets the id, name, and for properties (if they exist) to replace the "prefix" with the form's id number. This is where I ran into two issues.
Please let me know if you have any more questions or any suggestions. |
Could you put together a little example Django app that uses Trix (without your modifications) so I can see the problem in action? |
hi @javan |
Thanks! I don't think it makes sense to update Trix to work around an issue with Django's questionable admin JavaScript. Here's a potential solution you could add to your app or to the django-trix widget. I tested with the example app you created and it seems to work. addEventListener("trix-initialize", function(event) {
var trixElement = event.target
if (trixElement.getAttribute("input") == "id_child_set-__prefix__-content") {
var inputElement = trixElement.closest(".field-content").querySelector("textarea")
trixElement.setAttribute("input", inputElement.id)
}
}) |
Useful when using formset's in Django. Will attempt to find the element set by the name but if it does not exist, set's the element id to the default Django id format.
this connects to islco/django-trix#2