Django-autocomplete-light: tags overflow the input when using boostrap3

Created on 26 Mar 2020  路  2Comments  路  Source: yourlabs/django-autocomplete-light

My codes are relying on these things:
select2 4.0.10
jquery-3.1.1.min.js
django-autocomplete-light 3.5.1
django-bootstrap3 9.1.0

And when I select, the options selected are out of the input box:
image

Here is my code:

{% extends 'base.html' %}
{% load static %}
{% load i18n %}
{% load bootstrap3 %}
{% block custom_head_css_js %}
    <link href="{% static 'css/plugins/select2/select2.min.css' %}" rel="stylesheet">
    <script src="{% static 'js/plugins/select2/select2.full.min.js' %}"></script>
    <link href="{% static 'css/plugins/datepicker/datepicker3.css' %}" rel="stylesheet">
{% endblock %}

{% block content %}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>{{ action }}</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form method="post" class="form-horizontal" action="" >
                        {% if form.non_field_errors %}
                                <div class="alert alert-danger">
                                    {{ form.non_field_errors }}
                                </div>
                        {% endif %}
                        {% if form.errors %}
                                <div class="alert alert-danger">
                                    {{ form.errors }}
                                </div>
                        {% endif %}
                        {% csrf_token %}
                        {% bootstrap_field form.target_type layout="horizontal" %}
                        {% if target_type == request_target_type_servers %}
                            {% bootstrap_field form.servers layout="horizontal" %}
                        {% else %}
                            {% bootstrap_field form.nodes layout="horizontal" %}
                        {% endif %} 
                        <div class="form-group {% if form.date_expired.errors or form.date_start.errors %} has-error {% endif %}" id="date_5">
                            <label for="{{ form.date_expired.id_for_label }}" class="col-sm-2 control-label">{% trans 'Validity period' %}</label>
                            <div class="col-sm-9">
                                <div class="input-daterange input-group" id="datepicker">
                                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                    {% if form.errors %}
                                        <input type="text" class="input-sm form-control" id="date_start" name="date_start" value="{{ form.date_start.value }}">
                                        <span class="input-group-addon">to</span>
                                        <input type="text" class="input-sm form-control" id="date_expired" name="date_expired" value="{{ form.date_expired.value }}">
                                    {% else %}
                                        <input type="text" class="input-sm form-control" id="date_start" name="date_start" value="{{ form.date_start.value|date:'Y-m-d H:i' }}">
                                        <span class="input-group-addon">to</span>
                                        <input type="text" class="input-sm form-control" id="date_expired" name="date_expired" value="{{ form.date_expired.value|date:'Y-m-d H:i' }}">
                                    {% endif %}
                                </div>
                                <span class="help-block ">{{ form.date_expired.errors }}</span>
                                <span class="help-block ">{{ form.date_start.errors }}</span>
                            </div>
                            </div>
                        {% bootstrap_field form.comment layout="horizontal" %}

                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">
                                <button class="btn btn-white" type="reset">{% trans 'Reset' %}</button>
                                <button id="submit_button" class="btn btn-primary" type="submit">{% trans 'Submit' %}</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{% comment %} {% include 'assets/_asset_list_modal.html' %} {% endcomment %}
{% endblock %}
{% block custom_foot_js %}
<script src="{% static 'js/plugins/datepicker/bootstrap-datepicker.js' %}"></script>
<script type="text/javascript" src='{% static "js/plugins/daterangepicker/moment.min.js" %}'></script>
<script type="text/javascript" src='{% static "js/plugins/daterangepicker/daterangepicker.min.js" %}'></script>
{{ form.media }}
<link rel="stylesheet" type="text/css" href='{% static "css/plugins/daterangepicker/daterangepicker.css" %}' />

<script>
var dateOptions = {
    singleDatePicker: true,
    showDropdowns: true,
    timePicker: true,
    timePicker24Hour: true,
    autoApply: true,
    locale: {
        format: 'YYYY-MM-DD HH:mm'
    }
};
$(document).ready(function () {
    $('#date_start').daterangepicker(dateOptions);
    $('#date_expired').daterangepicker(dateOptions);
})
</script>
{% endblock %}

Do you have any idea on this?

Most helpful comment

Hi,
you need to add some custom CSS to your stylesheets.
I was able to fix it with the CSS below:

 /* dal bootstrap css fix */
.select2-container {
  width: 100% !important;
  min-width: 10em !important;
}
/* django-addanother bootstrap css fix */
.related-widget-wrapper{
  padding-right: 16px;
  position: relative;
}
.related-widget-wrapper-link{
  position: absolute;
  top: 3px;
  right: 0px;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
  line-height: 100% !important;
}

.select2-container .select2-selection--single {
  height: 40px !important;
}

.select2-container .select2-selection--multiple {

  min-height: 45px !important;
}

.select2-container--default .select2-selection--multiple .select2-selection__rendered {

  height: 100% !important;
}
.select2-container .select2-selection--multiple .select2-selection__rendered {
  overflow: auto !important;

}

All 2 comments

Hi,
you need to add some custom CSS to your stylesheets.
I was able to fix it with the CSS below:

 /* dal bootstrap css fix */
.select2-container {
  width: 100% !important;
  min-width: 10em !important;
}
/* django-addanother bootstrap css fix */
.related-widget-wrapper{
  padding-right: 16px;
  position: relative;
}
.related-widget-wrapper-link{
  position: absolute;
  top: 3px;
  right: 0px;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
  line-height: 100% !important;
}

.select2-container .select2-selection--single {
  height: 40px !important;
}

.select2-container .select2-selection--multiple {

  min-height: 45px !important;
}

.select2-container--default .select2-selection--multiple .select2-selection__rendered {

  height: 100% !important;
}
.select2-container .select2-selection--multiple .select2-selection__rendered {
  overflow: auto !important;

}

Thanks @josylad - it worked for me. I removed the part that referred to "height" because the vertical alignment was a bit off and I didn't have height problems.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ulziiburend picture ulziiburend  路  7Comments

mrname picture mrname  路  9Comments

Senpos picture Senpos  路  5Comments

durdenk picture durdenk  路  8Comments

VagnerNico picture VagnerNico  路  4Comments