Skip to content

Commit

Permalink
make it responsive. Only load select2 once to avoid flickering
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalfox committed Oct 17, 2024
1 parent b352555 commit 20102d0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
3 changes: 2 additions & 1 deletion leads/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ class LeadTagForm(forms.Form):
def __init__(self, *args, **kwargs):
lead = kwargs.pop("lead", None)
super(LeadTagForm, self).__init__(*args, **kwargs)
self.fields["tag"] = forms.ModelMultipleChoiceField(widget=LeadTagChoices(lead=lead), queryset=Tag.objects, label=False)
self.fields["tag"] = forms.ModelMultipleChoiceField(widget=LeadTagChoices(lead=lead, attrs={"data-placeholder": _("New tags"), "style": "min-width: 200px;"}),
queryset=Tag.objects, label=False)


class LeadForm(PydiciCrispyModelForm):
Expand Down
37 changes: 19 additions & 18 deletions templates/leads/_tags_banner.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,28 @@
{% load l10n %}

<div class="tag_banner alert" hx-target="this" hx-swap="outerHTML" hx-on::after-settle="$('.django-select2').djangoSelect2({ 'theme': 'bootstrap-5', 'width': 'auto'});">
<div class="d-flex flex-row">
<div id="newtags" class="d-flex flex-row align-self-center">
{% for tag in lead.tags.all %}
<div id="tag_{{ tag.id|unlocalize }}" class="mx-1">
<a href="{% url 'leads:tag' tag.id %}">{{ tag }}</a>
<a href='#' hx-delete="{% url 'leads:remove_tag' lead.id|unlocalize tag.id|unlocalize %}" >
<i class="bi bi-x-circle"></i></a>&nbsp;
<div class="row">
<div class="col-lg-auto col-md-12 align-self-center">
<div class="d-flex flex-wrap">
{% for tag in lead.tags.all %}
<div class="mx-1">
<a href="{% url 'leads:tag' tag.id %}">{{ tag }}</a>
<a href='#' hx-delete="{% url 'leads:remove_tag' lead.id|unlocalize tag.id|unlocalize %}" >
<i class="bi bi-x-circle"></i></a>&nbsp;
</div>
{% endfor %}
</div>
{% endfor %}
</div>
{% if perms.leads.change_lead %}
<div class="ms-3" >
<form id="tag_form">
<div class="row">
<div class="col">{{ lead_tag_form }}</div>
<div class="col"><button type="submit" class="btn btn-primary" hx-post="{% url 'leads:add_tag' lead.id|unlocalize %}">{% trans "Add" %}</button></div>
</div>
</form>
</div>

{% if perms.leads.change_lead %}
<div class="col-lg-auto col-md-12">
<form id="tag_form">
<div class="d-flex">
<div class="col">{{ lead_tag_form }}</div>
<div class="col"><button type="submit" class="btn btn-primary" hx-post="{% url 'leads:add_tag' lead.id|unlocalize %}">{% trans "Add" %}</button></div>
</div>
</form>
</div>
{% endif %}
</div>
{% if perms.leads.change_lead %}
Expand All @@ -34,4 +36,3 @@
{% endif %}
</div>

{% include "core/_select2.html" %}
1 change: 1 addition & 0 deletions templates/leads/lead_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
{% include "core/_billboard.html" %}
{% include "core/_pivotable_header.html" %}
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/masonry.pkgd.min.js" integrity="sha384-GNFwBvfVxBkLMJpYMOABq3c+d3KnQxudP/mGPkzpZSTYykLBNsZEnG2D9G/X/+7D" crossorigin="anonymous" async></script>
<script type="text/javascript" src="/static/django_select2/django_select2.js"></script>
{% endblock %}


Expand Down

0 comments on commit 20102d0

Please sign in to comment.