Crispy filter does not include form media after 1.6.0 release
See original GitHub issueThe crispy filter does not include a form’s media anymore since release 1.6.0. This appears to be a bug as in the previous release, 1.5.2, the crispy filter when applied to a form or formset’s context variable would include the form’s media when rendered.
In the template
{% load crispy_forms_filters %}
...
{{ form|crispy }}
Form class
class MyForm(forms.Form):
date=forms.DateField(
label='Approved',
required=True,
widget=DatePlaceholder,
)
...
The date field uses a widget that requires some javaScript and CSS to work correctly. These files are included in the form’s media when constructed in the view.
In version 1.5.2, this media would be included in the rendered html as seen below:
<link href="/path/to/jquery-ui-1.8.18.custom.css" type="text/css" media="all" rel="stylesheet">
<link href="/path/to/jquery-ui.css" type="text/css" media="all" rel="stylesheet">
<link href="/path/to/autocompleteselects.css" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="/path/to/jquery.autocompleteselects.js"></script>
<div id="div_id_approved_date" class="control-group">
<label for="id_approved_date" class="control-label ">
Approved
</label>
<div class="controls">
<input class="dateinputwithplaceholder input-block-level" id="id_approved_date" name="approved_date" placeholder="mm/dd/yyyy" type="text">
</div>
</div>
However, when using version 1.6.0, without changing any code, this is the rendered html:
<div id="div_id_approved_date" class="control-group">
<label for="id_approved_date" class="control-label ">
Approved
</label>
<div class="controls">
<input class="dateinputwithplaceholder input-block-level" id="id_approved_date" name="approved_date" placeholder="mm/dd/yyyy" type="text">
</div>
</div>
As you can see, the form media is no longer being included when being rendered by the filter.
This seems like it is a bug introduced between release 1.5.2 and 1.6.0.
It initially seems like this could be related to the changes from #525 with the optional inclusion of form media when using the crispy
template tag. Perhaps the include_media context variable is not being set correctly.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:7
Top GitHub Comments
(Initially leaning towards “Yes” — not least to encourage people not to use it 🙂)
Thanks for pointing that out! In my form,
self.helper.include_media
isTrue
, not from me setting it, but just from the initialization ofself.helper
withself.helper = FormHelper()
.I, like the original poster, was using the filter to render a form
{{ form|crispy }}
, perhaps mistakingly. The issue goes away (i.e. the form media is rendered) when I use the crispy tag{% crispy form %}
to show my form. Is that the desired behavior?