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).
This commit is contained in:
Christopher Charbonneau Wells 2017-09-17 15:48:23 -04:00
parent dad1ff73ca
commit 98963572ba
2 changed files with 13 additions and 22 deletions

View File

@ -28,12 +28,11 @@
<div class="input-group-addon" data-target="#datetimepicker_{{ field.name }}" data-toggle="datetimepicker">
<i class="fa fa-calendar"></i>
</div>
<input name="{{ field.html_name }}"
required="{{ field.required }}"
class="form-control datetimepicker-input{% if field.errors %} is-invalid{% endif %}"
data-target="#datetimepicker_{{ field.name }}"
id="id_{{ field.name }}"
type="text"/>
{% if field.errors %}
{{ field|add_class:"form-control is-invalid" }}
{% else %}
{{ field|add_class:"form-control" }}
{% endif %}
</div>
</div>
</div>

View File

@ -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',
}),
}