django-bootstrap-datepicker-plus icon indicating copy to clipboard operation
django-bootstrap-datepicker-plus copied to clipboard

Error "Uncaught TypeError: Cannot read property 'Constructor' of undefined at bootstrap datepicker"

Open pedrofaria09 opened this issue 3 years ago • 3 comments

Hi, I'm getting the error "Uncaught TypeError: Cannot read property 'Constructor' of undefined at bootstrap datepicker" and the date pop up doesn't work: Image

I start getting this error after updating all my packages to the last version on the project and after hours of research, I didn't find any solution. After I had the following versions, among others:

Django==2.1.7
django-bootstrap-datepicker-plus==3.0.5
django-bootstrap4==0.0.7

Now I have the following versions:

Django==3.1.7
django-bootstrap-datepicker-plus==3.0.5
django-bootstrap4==2.3.1

This is how my code is structured and was working perfectly on old packages versions:

  • main.html:
<head>
(some CSS's load's)
    {% load bootstrap4 %}
    {% bootstrap_css %}
    {% bootstrap_javascript jquery='full' %}
    {% block extrahead %}
        {{ form.media }}
    {% endblock %}
</head>


<body>
(...)
{% block content %}

{% endblock %}
(...)
    <script type="module" src="{% static 'vendor/jquery-easing/jquery.easing.min.js' %}"></script>

    <!-- Custom scripts for all pages-->
    <script type="module" src="{% static 'js/sb-admin-2.min.js' %}"></script>

    <!-- Page level plugins -->
    <script type="module" src="{% static 'vendor/datatables/jquery.dataTables.min.js' %}"></script>
    <script type="module" src="{% static 'vendor/datatables/dataTables.bootstrap4.min.js'%}"></script>

    <!-- Page level custom scripts -->
    <script type="module" src="{% static 'js/demo/datatables-demo.js' %}"></script>

    <!-- Deletes -->
    <script type="module" src="{% static 'js/deletes.js' %}"></script>

    <!-- Tables sort and search -->
    <script type="module" src="{% static 'js/tables-aux.js' %}"></script>

    <script type="module" src="{% static 'js/add_types.js' %}"></script>
    <script type="module" src="{% static 'js/defult.js' %}"></script>
</body>
(...)

content_page.html:

{% extends 'main.html' %}
{% load static %}
{% load widget_tweaks %}

{% block content %}

    <div class="container-fluid">
        <!-- Page Heading -->
        <div class="d-sm-flex align-items-center justify-content-between mb-4">
            <h1 class="h3 mb-0 text-gray-800">Associate Towers to a user</h1>
        </div>

        <div class="row">
            <div class="col-12">
                <form action="{% url "add_associate_towers" %}" method="POST">

                    {% csrf_token %}
                    {% if form.errors %}
                        {% for field in form %}
                            {% for error in field.errors %}
                                <div class="alert alert-danger">
                                    <strong>{{ field.label }} field have problem - {{ error|escape }} </strong>
                                </div>
                            {% endfor %}
                        {% endfor %}
                    {% endif %}

                    {% for field in form %}
                        <div class="form-group">
                            {% if field.field.is_checkbox %}
                                <div class="form-check">
                                    {{ field }}{% if field.field.required %} *{% endif %}
                                    {{ field.label_tag }}
                                </div>
                            {% else %}
                                {{ field.label_tag }} {% if field.field.required %} *{% endif %}
                                {% render_field  field placeholder=field.label %}
                            {% endif %}
                        </div>

                    {% endfor %}


                    <div class="form-group">
                        <div class="form-row">
                            <div class="col-md-12">
                                <input type="submit" class="btn btn-success btn-block" value="Submit">
                            </div>
                        </div>
                    </div>

                </form>
            </div>
        </div>
    </div>
    
{% endblock %}

Things I have done:

  • Comment all the js load and css and tried the troubleshooting from datepicker here and nothing
  • Already forced requirements.txt reinstallation.
  • Here says that I forgot to add bootstrap JavaScript file to the template but I already did and already changed all the load tags order.
  • I already added and removed the BOOTSTRAP4 = {'include_jquery': True,} from settings.py

I really hope someone can help me with this, maybe someone have a simple solution but I'm really not seeing it. For now, the only solution is to go back to the older packages versions I had before on requirements.txt.

Thanks in advance.

pedrofaria09 avatar Mar 17 '21 21:03 pedrofaria09

Same issue here, although I didn't change the Django or the DateTimePicker's versions. Instead, I changed the template version that I've been using. I think it has something to do with Bootstrap or JQuery since they got changed in my case due to template upgrade.

aiokaizen avatar Aug 11 '21 10:08 aiokaizen

Same issue here, although I didn't change the Django or the DateTimePicker's versions. Instead, I changed the template version that I've been using. I think it has something to do with Bootstrap or JQuery since they got changed in my case due to template upgrade.

The problem in my case was that bootstrap JS was not included in the page (partially integrated into the new template). So I solved the problem by including a full version in the template.

aiokaizen avatar Aug 11 '21 11:08 aiokaizen

I had the same problem. The problem was that {{ form.media }} included its javascript before bootstrap inclusion. I fixed it by moving the bootstrap inclusion code before in the html template.

davide-targa avatar Dec 13 '21 12:12 davide-targa

Same Issue here, but in admin form

from django import forms

class PersonForm(forms.ModelForm):
    class Meta:
        model = Person
        exclude = []

    birth_date = forms.DateField(widget=DatePickerInput(format='%m/%d/%Y'))

We had some updates in that issue?

Kalffman avatar Oct 29 '22 21:10 Kalffman

Closing pre v5 issues as stale. From v5 the error messages are more informative.

monim67 avatar Nov 26 '22 04:11 monim67