Skip to content
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

Feature Request: Add support for formsets/multiple of the same form #13

Open
Francois16 opened this issue Dec 31, 2024 · 1 comment
Open

Comments

@Francois16
Copy link

Problem: The django-tomselect package currently provides excellent integration of the Tom Select library with Django forms. However, it lacks support for Django formsets / using with multiple of the same form

Current Issue:
image

let wasReset{{ widget.name }} = false;
var {{ widget.name }} = new TomSelect(..., config);

Issue 1: It looks to be an issue with the way variable names are being set from the the widget.name rendering '-' which is causing the JS to break
Proposed solution: Perhaps add property onto the model to be used only for the variable names that replaces dashes -> underscores

Issue 2: It should also be able to handle copying the formset.empty_form which should initialize the widgets
Proposed solution: Honestly not sure how one would go about this

Issue 3: I've tried loading my forms independently using HTMX, this also does not work since having multiple of the same form Tomselect cannot differentiate between them i.e I have a button that adds a new form dynamically, the first form initializes correctly, when I add another form Tomselect cannot initialize it correctly.
Proposed solution: Perhaps initializing the Tomselects with a UUID of some kind using data attributes

image

@jacklinke
Copy link
Member

@Francois16 I had avoided this, mainly because I rarely use formsets myself.

But I figured it would be an easy update. Oops 😆

It involved a major rework of how tomselect.html is organized and the tomselect elements are initialized.

But it's working now in release 2025.1.2!

I haven't updated the docs to reflect the changes yet, but I did add tests along with two demos for the example app:

Enjoy, and let me know if you run into problems!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants