diff --git a/bootstrap4/bootstrap.py b/bootstrap4/bootstrap.py index 867e088b..837f0f8f 100644 --- a/bootstrap4/bootstrap.py +++ b/bootstrap4/bootstrap.py @@ -38,6 +38,7 @@ "javascript_in_head": False, "include_jquery": False, "use_i18n": False, + "use_javascript": True, "horizontal_label_class": "col-md-3", "horizontal_field_class": "col-md-9", "set_placeholder": True, diff --git a/bootstrap4/components.py b/bootstrap4/components.py index 20d085d5..d7ab4ed5 100644 --- a/bootstrap4/components.py +++ b/bootstrap4/components.py @@ -5,6 +5,7 @@ from bootstrap4.utils import render_tag, add_css_class from .text import text_value +from .bootstrap import get_bootstrap_setting def render_alert(content, alert_type=None, dismissable=True): @@ -15,7 +16,7 @@ def render_alert(content, alert_type=None, dismissable=True): if not alert_type: alert_type = "info" css_classes = ["alert", "alert-" + text_value(alert_type)] - if dismissable: + if dismissable and get_bootstrap_setting("use_javascript"): css_classes.append("alert-dismissable") button = ( ' + {% endif %} {% for error in errors %} {{ error }}{% if not forloop.last %}
{% endif %} {% endfor %} diff --git a/bootstrap4/templates/bootstrap4/messages.html b/bootstrap4/templates/bootstrap4/messages.html index bc030c53..e67d64f2 100644 --- a/bootstrap4/templates/bootstrap4/messages.html +++ b/bootstrap4/templates/bootstrap4/messages.html @@ -1,7 +1,9 @@ {% load bootstrap4 %} {% for message in messages %}
+ {% if 'use_javascript'|bootstrap_setting %} + {% endif %} {{ message }}
{% endfor %} diff --git a/bootstrap4/templatetags/bootstrap4.py b/bootstrap4/templatetags/bootstrap4.py index 57d5531a..103cf952 100644 --- a/bootstrap4/templatetags/bootstrap4.py +++ b/bootstrap4/templatetags/bootstrap4.py @@ -185,7 +185,10 @@ def bootstrap_javascript_url(): {% bootstrap_javascript_url %} """ - return javascript_url() + if not get_bootstrap_setting('use_javascript'): + return None + else: + return javascript_url() @register.simple_tag @@ -339,6 +342,9 @@ def bootstrap_javascript(jquery="falsy"): {% bootstrap_javascript jquery="slim" %} """ + if not get_bootstrap_setting('use_javascript'): + return None + # List of JS tags to include javascript_tags = [] diff --git a/docs/settings.rst b/docs/settings.rst index 705421ea..aa7abf45 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -26,6 +26,9 @@ The ``BOOTSTRAP4`` dict variable contains these settings and defaults: # The complete URL to the Bootstrap CSS file (None means no theme) 'theme_url': None, + # Whether to use any JavaScript at all + 'use_javascript': True, + # The complete URL to the Bootstrap JavaScript file (None means derive it from base_url) 'javascript_url': None,