From 2007f998cf1face62258e2e6b577c993fe40ccac Mon Sep 17 00:00:00 2001 From: "Christopher C. Wells" Date: Sat, 15 Apr 2023 12:58:41 -0700 Subject: [PATCH] Default datetime input to seconds granularity --- core/widgets.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/widgets.py b/core/widgets.py index d8d7867d..834d092d 100644 --- a/core/widgets.py +++ b/core/widgets.py @@ -116,6 +116,13 @@ class DateTimeBaseInput(widgets.DateTimeBaseInput): class DateTimeInput(DateTimeBaseInput): input_type = "datetime-local" + def build_attrs(self, base_attrs, extra_attrs=None): + attrs = super().build_attrs(base_attrs, extra_attrs) + # Default to seconds granularity. Required for client validation in Safari. + if "step" not in attrs: + attrs["step"] = 1 + return attrs + class DateInput(DateTimeBaseInput): input_type = "date"