scott
scott

Reputation: 1194

django-select2-forms autocomplete options render in admin panel but not in inline form

I'm using the django-select2-forms library and Django 1.11 and the select2 form autosuggests and completes perfectly in the Django admin panel, but on my HTML page it doesn't.

In HTML, i'm inserting my form with:

{{forms.media}}
{{forms.tags}}

forms.py

tags = select2.fields.MultipleChoiceField(Tag,overlay="Choose several skills...")

models.py

tags = select2.fields.ManyToManyField(Tag,overlay="Choose several skills...",ajax=True,search_field="name")

Is my forms.py accurate? The documentation for this library is scarce and I've been working hours on this problem.

Upvotes: 0

Views: 1096

Answers (1)

Dean Sherwin
Dean Sherwin

Reputation: 498

Just spent a couple of hours trying to figure this one out and came across your question in the process. Figured I'd post the solution:

It seems that django-select2-forms does load all static files for select2 in the default django-admin site because typically the developer would not edit those templates.

However, for our own templates we have to include the CSS and JS ourselves.

Do this by adding {{form.media.css}} in your <head> and {{form.media.js}} in the footer of your base.html template or wherever you're bringing in your other CSS and Javascript.

It's astounding that such a crucial step is not mentioned anywhere in the docs for this package.

Upvotes: 3

Related Questions