I am using the jQuery datePicker to gather date input. I am able to see the calendar show on the Appointment form and am able to select a date from the calendar. However, once submitted, I am not able to extract the selected date, in the post processing function.
I have read somewhere about form field not being extractable if user did not enter a value. In my scenario, I don't manually enter "perfDate", but rather made a selection on the calendar. I get KeyError on trying to read the field value. The Django debugs show that the POST data as shown here-
POST
Variable Value csrfmiddlewaretoken perfDate
class DateInput(forms.DateInput):input_type = 'date'class AppointmentForm(forms.Form):class Meta:model = Appointmentwidgets = {'perfDate': forms.DateInput(attrs={'class':'datepicker'}),}
<!doctype html><html lang="en"><head>... JS code...</head><body><form action="/users/makeReservation/" method="post">{% csrf_token %}<!--{{ form.date }} --><p>Desired date:<p><input name="perfDate" type="text" id="id_date"></p><!-- The rest of my form --><input type="submit" value="Reserve" /></form></body>
def makeReservation(request):if request.method == 'POST':aptForm = AppointmentForm(request.POST)# Have we been provided with a valid form?if aptForm.is_valid():aptDate = aptForm.cleaned_data['perfDate'])...else:# The supplied form contained errors - just print them to the terminal.print(form.errors)else:aptForm = AppointmentForm(request.POST)return render(request, 'datePicker.html', {'form' : aptForm})