I overrided time input widget but when i submit that form, ‘Enter a valid time’ is shown
class TimePickerWidget(forms.TimeInput):
def render(self, name, value, attrs=None):
htmlString = u''
htmlString += u'<select name="%s">' % (name)
for i in range(12):
htmlString += ('<option value="%d:00 AM">%d:00 AM</option>' % (i,i))
htmlString +='</select>'
return mark_safe(u''.join(htmlString))
as you see, it make drop-down box for time select. in form, it is called by
class JobForm (ModelForm):
fromHour = forms.TimeField(widget=TimePickerWidget(format='%I:%M %p'))
toHour = forms.TimeField(widget=TimePickerWidget(format='%I:%M %p'))
I have two questions.
1) When i submit, ‘ ‘Enter a valid time’ is shown. How can i solve this?
2) Is there any way to encapsule that format=’%I:%M %p’ format to the TimePicketWidget?
Set
input_formatargument to TimeField, ie: