From 98963572ba12aeb989b620a67d4ef71cb589ade7 Mon Sep 17 00:00:00 2001 From: Christopher Charbonneau Wells Date: Sun, 17 Sep 2017 15:48:23 -0400 Subject: [PATCH] Use form classes to set appropriate field attributes in date/time fields. Using a custom input element in the template caused issues with default values (e.g. when set by a timer). --- babyblotter/templates/babyblotter/form.html | 11 +++++----- core/forms.py | 24 +++++++-------------- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/babyblotter/templates/babyblotter/form.html b/babyblotter/templates/babyblotter/form.html index 36e162f1..ac485edb 100644 --- a/babyblotter/templates/babyblotter/form.html +++ b/babyblotter/templates/babyblotter/form.html @@ -28,12 +28,11 @@
- + {% if field.errors %} + {{ field|add_class:"form-control is-invalid" }} + {% else %} + {{ field|add_class:"form-control" }} + {% endif %} diff --git a/core/forms.py b/core/forms.py index c05dd401..8d101d4d 100644 --- a/core/forms.py +++ b/core/forms.py @@ -44,8 +44,7 @@ class ChildForm(forms.ModelForm): widgets = { 'birth_date': forms.DateInput(attrs={ 'class': 'datepicker-input', - 'data-toggle': 'datetimepicker', - 'data-target': '#id_birth_date', + 'data-target': '#datetimepicker_date', }), } @@ -57,8 +56,7 @@ class DiaperChangeForm(forms.ModelForm): widgets = { 'time': forms.DateTimeInput(attrs={ 'class': 'datepicker-input', - 'data-toggle': 'datetimepicker', - 'data-target': '#id_time', + 'data-target': '#datetimepicker_time', }), } @@ -74,13 +72,11 @@ class FeedingForm(forms.ModelForm): widgets = { 'start': forms.DateTimeInput(attrs={ 'class': 'datepicker-input', - 'data-toggle': 'datetimepicker', - 'data-target': '#id_start', + 'data-target': '#datetimepicker_start', }), 'end': forms.DateTimeInput(attrs={ 'class': 'datepicker-input', - 'data-toggle': 'datetimepicker', - 'data-target': '#id_end', + 'data-target': '#datetimepicker_end', }), } @@ -106,13 +102,11 @@ class SleepForm(forms.ModelForm): widgets = { 'start': forms.DateTimeInput(attrs={ 'class': 'datepicker-input', - 'data-toggle': 'datetimepicker', - 'data-target': '#id_start', + 'data-target': '#datetimepicker_start', }), 'end': forms.DateTimeInput(attrs={ 'class': 'datepicker-input', - 'data-toggle': 'datetimepicker', - 'data-target': '#id_end', + 'data-target': '#datetimepicker_end', }), } @@ -154,13 +148,11 @@ class TummyTimeForm(forms.ModelForm): widgets = { 'start': forms.DateTimeInput(attrs={ 'class': 'datepicker-input', - 'data-toggle': 'datetimepicker', - 'data-target': '#id_start', + 'data-target': '#datetimepicker_start', }), 'end': forms.DateTimeInput(attrs={ 'class': 'datepicker-input', - 'data-toggle': 'datetimepicker', - 'data-target': '#id_end', + 'data-target': '#datetimepicker_end', }), }