I have a django form which as two date fields. I am trying to have a Calendar Pop-up with the default date being sent on click as ("yyyy-mm-dd"). I have tried this several ways, changed the setting in the javascript, changed the django settings file, but no matter what the form says invalid date and the date format that gets sent to the field always is mm/dd/yyyy.
Here is an example of the code In the form I have:
from django import forms
from functools import partial
DateInput = partial(forms.DateInput, {'class': 'datepicker'})
class SearchForm(forms.Form):
start_date = forms.DateField(widget=DateInput(format = '%Y-%m-%d'),
required=False,
input_formats=['%Y-%m-%d'])
end_date = forms.DateField(widget=DateInput(format = '%Y-%m-%d'),
required=False,
input_formats=['%Y-%m-%d'])
My tempplate has the following:
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
<script>
$(document).ready(function() {
$('.datepicker').datepicker()
});
</script>
<TR>
<TD COLSPAN="3" ALIGN="Center"> Start Date: {{ form.start_date }}
End Date: {{ form.end_date }}
Date Format <B>MUST</B> be YYYY-MM-DD<br>
Dates are inclusive.<br>
If a date is left blank it is assumed to go until the start or end.</TD>
</TR>
I have tried putting dateFormat('yyyy-mm-dd') inside the datepicker code , as well as format('yyyy-mm-dd'), format('yy-mm-dd'). None of them changes the way to date is sent to the field, it's always "mm/dd/yyyy'. The form says this is not a valid date.
I know there are posts about this, but none of the ones I have tried have changed the outcome.