From 86861aa28f291ce08f4d1c234a6d4989cc4c7dc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 13 Nov 2018 21:33:55 +0100 Subject: [PATCH] manager: switch time selection to the html5 time input widget (#13603) --- chrono/manager/widgets.py | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/chrono/manager/widgets.py b/chrono/manager/widgets.py index b8eb9998..e7247628 100644 --- a/chrono/manager/widgets.py +++ b/chrono/manager/widgets.py @@ -130,27 +130,18 @@ class DateTimeWidget(PickerWidgetMixin, DateTimeInput): super(DateTimeWidget, self).__init__(attrs, options, usel10n) -class TimeWidget(PickerWidgetMixin, TimeInput): +class TimeWidget(TimeInput): """ - TimeWidget is the corresponding widget for Time field, it renders only the time section of - datetime picker. + TimeWidget is a widget for time selection, it uses the HTML5 "time" + input type and has a bit of a fallback mechanism with the presence + of the pattern attribute in case a standard text input is used. """ + input_type = 'time' - format_name = 'TIME_INPUT_FORMATS' - glyphicon = 'glyphicon-time' - - def __init__(self, attrs=None, options=None, usel10n=None): - - if options is None: - options = {} - - # Set the default options to show only the timepicker object - options['startView'] = options.get('startView', 1) - options['minView'] = options.get('minView', 0) - options['maxView'] = options.get('maxView', 1) - options['format'] = options.get('format', 'hh:ii') - - super(TimeWidget, self).__init__(attrs, options, usel10n) + def __init__(self, **kwargs): + super(TimeWidget, self).__init__(**kwargs) + self.attrs['step'] = '300' # 5 minutes + self.attrs['pattern'] = '[0-9]{2}:[0-9]{2}' class WeekdaysWidget(SelectMultiple):