In my simple Django App, I've implemented django-select2. I have a form with 2 fields: product and category. When I create a new product I first give it a title and than tab to the category-field, but the dropdown does not open automatically. Only when I press Space-Bar or Enter the dropdown opens.
What can I do so that the dropdown opens automatically, when it is reached?
Here my code:
forms.py
from django import forms
from django_select2.forms import Select2Widget, ModelSelect2Widget, Select2MultipleWidget
from .models import Product, Category
class MyForm(forms.ModelForm):
category = ModelSelect2Widget(queryset=Category.objects.all())
class Meta:
model = Product
fields = ['name', 'category']
widgets = {
'category': Select2Widget,
}
models.py
from django.db import models
class Category(models.Model):
name = models.CharField(max_length=50)
def __str__(self):
return self.name
class Product(models.Model):
name = models.CharField(max_length=120)
category = models.ForeignKey(Category, on_delete=models.CASCADE)
def __str__(self):
return self.name
product.html
{% extends 'base.html' %}
{% block content %}
{{ form.media.css }}
<br>
<form action="" method="POST">
{% csrf_token %}
{{ form}}
<button type="submit">Save</button>
</form>
{{ form.media.js }}
{% endblock content %}