The Django DateInput widget doesn't render anything but a plain text input. It does however validate the user's input against a variety of formats, so it's not useless.
Most people would expect it to behave in the same way as the date picker found in the Django Admin interface, so it's definitely a little confusing.
It is possible to use the AdminDateWidget in your own apps, but I would advise against it. It takes a lot of fiddling around to make it work.
The easiest solution is to use something like the JQuery UI Datepicker. Simply include the following in the <head>
of your page:
<link type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/themes/redmond/jquery-ui.css" rel="Stylesheet" />
<script language="javascript" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js"></script>
Then at the bottom, put the following line to activate the Datepicker on your input elements:
<script type="text/javascript">
$(function(){
$("#id_birthday").datepicker();
});
</script>
You can make this a little more DRY if you have many date fields by creating a custom widget in your forms.py
:
class JQueryUIDatepickerWidget(forms.DateInput):
def __init__(self, **kwargs):
super(forms.DateInput, self).__init__(attrs={"size":10, "class": "dateinput"}, **kwargs)
class Media:
css = {"all":("http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/themes/redmond/jquery-ui.css",)}
js = ("http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js",
"http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js",)
Specify each date field should use this widget in your forms:
birthday = forms.DateField(label="Birthday", widget=JQueryUIDatepickerWidget)
And in your template, include the following in the <head>
:
{{form.media}}
And activate the Datepicker for all fields by putting the following at the bottom of the page:
<script type="text/javascript">
$(function(){
$(".dateinput").datepicker();
});
</script>