Last active
October 9, 2021 19:56
-
-
Save maraujop/2812529 to your computer and use it in GitHub Desktop.
Datepicker template for django-crispy-forms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% load crispy_forms_field %} | |
<div id="div_{{ field.auto_id }}" class="control-group{% if form_show_errors and field.errors %} error{% endif %} {% if field.field.widget.attrs.class %} {{ field.field.widget.attrs.class }}{% endif %}"> | |
{% if field.label %} | |
<label for="{{ field.id_for_label }}" class="control-label {% if field.field.required %}requiredField{% endif %}"> | |
{{ field.label|safe }}{% if field.field.required %}<span class="asteriskField">*</span>{% endif %} | |
</label> | |
{% endif %} | |
<div class="controls"> | |
<div class="input-append"> | |
{% crispy_field field %} | |
<span class="add-on {% if active %}active{% endif %}">{{ crispy_appended_text|safe }}</span> | |
</div> | |
{% include 'bootstrap/layout/help_text_and_errors.html' %} | |
</div> | |
</div> | |
<!-- | |
To be used with bootstrap-datepicker and Django DateField. | |
http://www.eyecon.ro/bootstrap-datepicker/ | |
In your layout do: `Field('field_name', template='date.html')` | |
Make sure date.html is in your templates path. You could build a custom layout object inheriting from `Field` named `DateField` that could get parameters passed for `data-date` and `data-date-format` for example. | |
--> |
It goes in a file called date.html with the other templates , then in the field you add template='date.html' in the form helper layout section
I get an error when trying to use Field(..., template='date.html')
in my forms.py
VariableDoesNotExist at /events/create
Failed lookup for key [field]
Generated by line 13 of your template
{% crispy_field field %}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've been struggling with this for a year now! Where should I put EugeneDae's js code? Does it go in forms.py, or on each html page which needs a datetimepicker?