I have a Django form, with a date field displayed on it, which has a data type of mDateField
(a custom class that extends forms.DateField
). It is defined in forms.py with:
class mDateField(forms.DateField):
def __init__(self, *args, **kwargs):
kwargs.setdefault('input_formats', DATE_INPUT_FORMATS)
super(mDateField, self).__init__(*args, **kwargs)
I now want to set a 'minimum' & 'maximum' possible value for that date field (i.e. a date a certain length of time either in the past or in the future relevant to today's date that this value can be set to).
I came across this answer on SO: jquery datetime picker set minDate dynamic and tried following what it says, by writing the line:
presentation_date = mDateTimeField(required=False, widget=forms.DateTimeInput(format='%d/%m/%Y %H:%M', attrs=({'class':'datetimepicker presentation_date', 'name':'presentation_date2'})))
presentation_date.options.maxDate = $( ".selector" ).datepicker( "option", "maxDate", new Date(2014, 1 - 1, 1));
but when I do, I get a syntax error in the console, which points to the $
, and says:
SyntaxError: invalid syntax
What is wrong with what I'm doing here? How can I specify what the earliest/ latest date to be shown in the datepicker
should be?
Edit In the jQuery file where datetimepicker
is defined (jquery.datetimepicker.full.js), there are the following lines:
if (options.minDate && /^[\+\-](.*)$/.test(options.minDate)) {
options.minDate = dateHelper.formatDate(_xdsoft_datetime.strToDateTime(options.minDate), options.formatDate);
}
if (options.maxDate && /^[\+\-](.*)$/.test(options.maxDate)) {
options.maxDate = dateHelper.formatDate(_xdsoft_datetime.strToDateTime(options.maxDate), options.formatDate);
}
But I don't see how these are setting the values to any actual dates...?