Ability to reinitialize a formset and input widgets after page has loaded? #100
Replies: 5 comments 5 replies
-
Hi @SSJenny90 , |
Beta Was this translation helpful? Give feedback.
-
(reposting as a top level comment) Totally agree that both technologies fit well together. Here's a demo app as requested: https://github.com/SSJenny90/django-formset It adds an additional HTMXFormView that shows up as "htmx" under the index view of each framework. I configured it with the OpinionForm because that was the first I found that utilized the Selectize widgets in order to demonstrate the issue. The new view should happily work with any other form as required. If you need anything else or require more explanation, let me know. |
Beta Was this translation helpful? Give feedback.
-
This is a truly exceptional library @jrief... thought all my dreams had come truebut I too use HTMX extensively and it's not at all straightforward. Well done though. Great work. |
Beta Was this translation helpful? Give feedback.
-
What should such a I actually am more focused on using the PEG-parser to create my own triggers in analogy to the HTMX triggers. Maybe you could describe some use cases, how your project works. I currently have a long backlog, so please be patient. |
Beta Was this translation helpful? Give feedback.
-
I don't normally venture far into the JS/TS world but I took a look at django-formset.ts and django-formset.monlith.ts, and noticed that all of the init logic happens directly inside a 'DOMContentLoaded' listener. Would it be possible to pull this code out into a function and then expose the function to the global window object? Something like this: // django-formset.ts
function initializeFormset() {
// all initiliazation logic here
}
window.addEventListener('DOMContentLoaded', (event) => {
intializeFormset();
}
// Attach the function to the global `window` object
window.initializeFormset = initializeFormset; In this case, all someone needs to do in their page is recall the initializeFormset method when it suits them (e.g. inside an HTMX event listener). I'm sure there's more to it than this but maybe it gets us moving towards a solution. |
Beta Was this translation helpful? Give feedback.
-
Hi jrief,
I'm trying to add some some interactivity to my app using htmx to inject forms into an existing web page. I have a formset that works fine when I use it normally, however, if I inject that same form using htmx, some of the widgets (e.g. selectize, rich text, etc.) do not render properly on the page.
Not raising an issue because this is probably outside the expected use case of django-formset. But perhaps you have some ideas? Is there a way to re-initialize a formset after the page has already loaded?
Normal use (works fine):
HTMX injection after page load (not so good):
Beta Was this translation helpful? Give feedback.
All reactions