Date Picker

Last Updated: August 10, 2015

class tethys_sdk.gizmos.DatePicker(name, display_text='', autoclose=False, calendar_weeks=False, clear_button=False, days_of_week_disabled='', end_date='', format='', min_view_mode='days', multidate=1, start_date='', start_view='month', today_button=False, today_highlight=False, week_start=0, initial='', disabled=False, error='', attributes={}, classes='')

Date pickers are used to make the input of dates streamlined and easy. Rather than typing the date, the user is presented with a calendar to select the date. This date picker was implemented using Bootstrap Datepicker.

name

Name of the input element that will be used for form submission.

Type:str, required
display_text

Display text for the label that accompanies date picker.

Type:str
autoclose

Set whether datepicker auto closes when a date is selected.

Type:bool
calendar_weeks

Set whether calendar week numbers are shown on the left of the datepicker.

Type:bool
clear_button

Set whether the clear button is displayed or not.

Type:bool
days_of_week_disabled

Days of the week that are disabled 0-6 with 0 being Sunday and 6 being Saturday. Multiple days are comma separated (e.g.: '0,6').

Type:str
end_date

Last date that can be selected. All other dates after this date are shown as disabled.

Type:str
format

String representing date format. For valid formats see Bootstrap Datepicker documentation here.

Type:str
min_view_mode

Set the minimum view mode. Possible values are 'days', 'months', 'years'.

Type:str
multidate

Enables multi-selection of dates up to the number given.

Type:int
start_date

First date that can be selected. All other dates before this date are shown as disabled.

Type:str
start_view

View the date picker starts on. Valid values include 'month', 'year', and 'decade'.

Type:str
today_button

Set whether a today button is displayed or not.

Type:bool
today_highlight

Set whether to highlight the current date.

Type:bool
week_start

Set the day the week starts on 0-6, where 0 is Sunday and 6 is Saturday.

Type:int
initial

Initial date to appear in date picker.

Type:str
disabled

Disabled state of the date picker.

Type:bool
error

Error message for form validation.

Type:str
attributes

A dictionary representing additional HTML attributes to add to the primary element (e.g. {"onclick": "run_me();"}).

Type:dict
classes

Additional classes to add to the primary HTML element (e.g. "example-class another-class").

Type:str

Controller Example

from tethys_sdk.gizmos import DatePicker

# Date Picker Options
date_picker = DatePicker(name='date1',
                         display_text='Date',
                         autoclose=True,
                         format='MM d, yyyy',
                         start_date='2/15/2014',
                         start_view='decade',
                         today_button=True,
                         initial='February 15, 2014')

date_picker_error = DatePicker(name='data2',
                               display_text='Date',
                               initial='10/2/2013',
                               disabled=True,
                               error='Here is my error text.')

context = {
            'date_picker': date_picker,
            'date_picker_error': date_picker_error,
          }

Template Example

{% load tethys_gizmos %}

{% gizmo date_picker %}
{% gizmo date_picker_error %}