djangoのjsCalendarのwidget


formに時間を入力するには

class JsCalendarWidget(forms.TextInput):
    class Media:
        js = (
              settings.MEDIA_URL+"js/jscalendar/calendar_stripped.js",
              settings.MEDIA_URL+"js/jscalendar.setup.js",
              settings.MEDIA_URL+"js/jscalendar/calendar-setup_stripped.js",
              settings.MEDIA_URL+"js/jscalendar/lang/calendar-en.js",             
              )
        css = {
                 'all': (settings.MEDIA_URL+'/js/jscalendar/skins/aqua/theme.css',)
               }

    def __init__(self, attrs={}):
      super(JsCalendarWidget, self).__init__(attrs)
   
class IssueForm(ModelForm):
    issue_occur_date =  forms.DateTimeField(widget=JsCalendarWidget(attrs={'class':'vDateField','size':'50'}))


対応するjs設定コードは:

function initCalendar() {
  Calendar.setup(
    {
      inputField : "id_issue_occur_date", //      
      ifFormat    : "%Y-%m-%d %H:%M:%S",
      button      : "trigger"
    }
  );
}

if(document.all) {
  window.attacheEvent('onload',initCalendar);
} else {
  window.addEventListener('load',initCalendar,false);
}