Features: 1) Add required static asset links for Select2 styles and scripts; 2) Enhance autocomplete list filter with improved styles and functionality;
Fixes: 1) Fix indentation inconsistencies in HTML template; Extra: 1) Refactor inline script for improved readability;
This commit is contained in:
parent
efcbfea825
commit
1116d6c602
1 changed files with 23 additions and 16 deletions
|
|
@ -1,27 +1,34 @@
|
|||
{% load i18n static %}
|
||||
|
||||
<link rel="stylesheet"
|
||||
href="{% static 'admin/css/vendor/select2/select2.css' %}"/>
|
||||
<link rel="stylesheet"
|
||||
href="{% static 'admin/css/autocomplete.css' %}"/>
|
||||
|
||||
<script src="{% static 'admin/js/vendor/select2/select2.full.js' %}"></script>
|
||||
<script src="{% static 'admin/js/jquery.init.js' %}"></script>
|
||||
<script src="{% static 'admin/js/autocomplete.js' %}"></script>
|
||||
|
||||
<div class="filter-autocomplete">
|
||||
<select name="{{ spec.lookup_kwarg }}"
|
||||
id="id_{{ spec.lookup_kwarg }}"
|
||||
class="admin-autocomplete"
|
||||
style="width:90%;"
|
||||
data-ajax--url="{{ spec.autocomplete_url }}"
|
||||
data-app-label="{{ spec.app_label }}"
|
||||
data-model-name="{{ spec.model_name }}"
|
||||
data-field-name="{{ spec.field_name }}"
|
||||
data-allow-clear="true"
|
||||
data-placeholder="{% blocktrans with label=spec.field_label %}Search by {{ label }}…{% endblocktrans %}">
|
||||
<select
|
||||
name="{{ spec.lookup_kwarg }}"
|
||||
id="id_{{ spec.lookup_kwarg }}"
|
||||
class="admin-autocomplete"
|
||||
style="width:90%;"
|
||||
data-ajax--url="{{ spec.autocomplete_url }}"
|
||||
data-app-label="{{ spec.app_label }}"
|
||||
data-model-name="{{ spec.model_name }}"
|
||||
data-field-name="{{ spec.field_name }}"
|
||||
data-allow-clear="true"
|
||||
data-placeholder="{% blocktrans with label=spec.field_label %}Search by {{ label }}…{% endblocktrans %}">
|
||||
{% if spec.lookup_val %}
|
||||
<option value="{{ spec.lookup_val }}" selected>{{ spec.initial_text }}</option>
|
||||
{% endif %}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<link rel="stylesheet" href="{% static 'admin/css/autocomplete.css' %}"/>
|
||||
|
||||
{# Only our own bootstrap script, using django.jQuery #}
|
||||
<script>
|
||||
(function ($) {
|
||||
$('.admin-autocomplete').djangoAdminSelect2();
|
||||
})(django.jQuery);
|
||||
(function($) {
|
||||
$('.admin-autocomplete').djangoAdminSelect2();
|
||||
})(django.jQuery);
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Reference in a new issue