I have troubles styling django-selectable.
Currently, without any styling work, the search result dropdown list would appear on a transparent background. And I noticed that I when specifying the
get_item_label method, I can include HTML there. So I have been experimenting adding HTML tags to style the dropdown list. And here is my main part of code.
# lookups.py
from selectable.base import ModelLookup
from selectable.registry import registry
from .models import Topic
class TopicLookup(ModelLookup):
model = Topic
search_fields = ('name__icontains', )
def get_item_label(self, item):
"""The label is shown in the drop down menu of search results."""
return '<strong>%s</strong>' % item.name
def get_item_value(self, item):
"""The id is the value that will eventually be returned by the field/widget."""
return item.name
def get_item_value(self, item):
"""The value is shown in the input once the item has been selected."""
return item.name
registry.register(TopicLookup)
# forms.py
from django.forms import ModelForm
from charsleft_widget.widgets import CharsLeftArea
from .models import Topic, LessonsLearned
from .lookups import TopicLookup
class LessonsLearnedForm(ModelForm):
topic = AutoCompleteSelectField(lookup_class=TopicLookup, allow_new=True)
class Meta:
model = LessonsLearned
exclude = ['creator', 'topic']
labels = {
'text': "Lessons learned",
}
widgets = {
'text': CharsLeftArea(
attrs={'placeholder': '%d characters max...' % model._meta.get_field('text').max_length}
),
}
def __init__(self, *args, **kwargs):
super(LessonsLearnedForm, self).__init__(*args, **kwargs)
if self.instance and self.instance.pk and self.instance.topic:
self.initial['topic'] = self.instance.topic
def save(self, *args, **kwargs):
topic = self.cleaned_data['topic']
if topic and not topic.pk:
topic = Topic.objects.create(name=topic.name)
self.instance.topic = topic
return super(LessonsLearnedForm, self).save(*args, **kwargs)
But the result is not as expected, the <strong>...</strong> tags were not parsed as HTML tags, as shown in the following screenshot.

My questions are:
Am I doing something wrong?
Is the get_item_label method designed to be a handy way to style the item labels in the dropdown list without touching any Javascript?
And is it possible to style them without touching any Javascript?
Hopefully I am describing my issue in enough detail. Please help me.