diff --git a/babybuddy/static_src/scss/forms.scss b/babybuddy/static_src/scss/forms.scss index a374a6ec..3a0d8705 100644 --- a/babybuddy/static_src/scss/forms.scss +++ b/babybuddy/static_src/scss/forms.scss @@ -51,4 +51,10 @@ padding: 0.25rem 0.5rem; position: relative; } +} + +form .row details { + // removing this causes slight mis-alignment between fields in the details and the rest of the fields + //on the form at the left hand side of the box + padding-right: 0; } \ No newline at end of file diff --git a/babybuddy/templates/babybuddy/base.html b/babybuddy/templates/babybuddy/base.html index bf7a029c..f785dc2e 100644 --- a/babybuddy/templates/babybuddy/base.html +++ b/babybuddy/templates/babybuddy/base.html @@ -44,6 +44,22 @@ {% if user.is_authenticated %}{% endif %} - {% block javascript %}{% endblock %} + {% block javascript %} + + {% endblock %} diff --git a/babybuddy/templates/babybuddy/form_field.html b/babybuddy/templates/babybuddy/form_field.html index 41509f78..c454a5e0 100644 --- a/babybuddy/templates/babybuddy/form_field.html +++ b/babybuddy/templates/babybuddy/form_field.html @@ -5,35 +5,6 @@ {{ field.label }}
- {% if field|field_type == "booleanfield" %} - {% if field.errors %} - {{ field|add_class:"btn-check is-invalid" }} - {% else %} - {{ field|add_class:"btn-check" }} - {% endif %} - - {% elif 'choice' in field|field_type %} - {% if field.errors %} - {{ field|add_class:"form-select is-invalid" }} - {% else %} - {{ field|add_class:"form-select" }} - {% endif %} - {% else %} - {% if field.errors %} - {{ field|add_class:"form-control is-invalid" }} - {% else %} - {{ field|add_class:"form-control" }} - {% endif %} - {% endif %} - {% if field.help_text %} -
- {{ field.help_text }} -
- {% endif %} - {% if field.errors %} -
- {% for error in field.errors %}{{ error }}{% endfor %} -
- {% endif %} + {% include 'babybuddy/form_field_no_label.html' %}
diff --git a/core/forms.py b/core/forms.py index a1f283c5..0a98fdcb 100644 --- a/core/forms.py +++ b/core/forms.py @@ -178,6 +178,11 @@ class TaggableModelForm(forms.ModelForm): class PumpingForm(CoreModelForm, TaggableModelForm): + fieldsets = [ + {"fields": ["child", "start", "end", "amount"], "layout": "required"}, + {"layout": "advanced", "fields": ["notes", "tags"]}, + ] + class Meta: model = models.Pumping fields = ["child", "start", "end", "amount", "notes", "tags"] @@ -190,6 +195,16 @@ class PumpingForm(CoreModelForm, TaggableModelForm): class DiaperChangeForm(CoreModelForm, TaggableModelForm): + fieldsets = [ + { + "fields": ["wet", "solid"], + "layout": "choices", + "layout_attrs": {"label": "Contents"}, + }, + {"fields": ["child", "time"], "layout": "required"}, + {"layout": "advanced", "fields": ["notes", "tags"]}, + ] + class Meta: model = models.DiaperChange fields = ["child", "time", "wet", "solid", "color", "amount", "notes", "tags"] @@ -213,6 +228,14 @@ class FeedingForm(CoreModelForm, TaggableModelForm): class BottleFeedingForm(CoreModelForm, TaggableModelForm): + fieldsets = [ + { + "fields": ["child", "type", "start", "amount"], + "layout": "required", + }, + {"layout": "advanced", "fields": ["notes", "tags"]}, + ] + def save(self): instance = super(BottleFeedingForm, self).save(commit=False) instance.method = "bottle" diff --git a/core/templates/forms/layouts/advanced.html b/core/templates/forms/layouts/advanced.html new file mode 100644 index 00000000..2513befa --- /dev/null +++ b/core/templates/forms/layouts/advanced.html @@ -0,0 +1,10 @@ +
+
+
+ Advanced + {% for field in fieldset.fields %} +
{% include "babybuddy/form_field.html" %}
+ {% endfor %} +
+
+
diff --git a/core/templates/forms/layouts/choices.html b/core/templates/forms/layouts/choices.html new file mode 100644 index 00000000..8b74202f --- /dev/null +++ b/core/templates/forms/layouts/choices.html @@ -0,0 +1,9 @@ +{% load i18n %} +
+ +
+ {% for field in fieldset.fields %} + {% include "babybuddy/form_field_no_label.html" %} + {% endfor %} +
+
diff --git a/core/templates/forms/layouts/required.html b/core/templates/forms/layouts/required.html new file mode 100644 index 00000000..6bbcf479 --- /dev/null +++ b/core/templates/forms/layouts/required.html @@ -0,0 +1,3 @@ +{% for field in fieldset.fields %} +
{% include "babybuddy/form_field.html" %}
+{% endfor %}