From 8f477dd6f15c5e3f940870fac6206f97dc9fb3f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Wed, 22 Mar 2023 19:36:41 +0800 Subject: [PATCH] Added the all_errors pseudo property to the RecurringItemForm form, and applied it to the form-recurring-item.html template. --- src/accounting/option/forms.py | 13 +++++++++++++ .../option/include/form-recurring-item.html | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/accounting/option/forms.py b/src/accounting/option/forms.py index 11d6a32..b762cda 100644 --- a/src/accounting/option/forms.py +++ b/src/accounting/option/forms.py @@ -20,6 +20,7 @@ import re from flask import render_template +from flask_babel import LazyString from flask_wtf import FlaskForm from wtforms import StringField, FieldList, FormField, IntegerField from wtforms.validators import DataRequired, ValidationError @@ -119,6 +120,18 @@ class RecurringItemForm(FlaskForm): account: Account | None = Account.find_by_code(self.account_code.data) return None if account is None else str(account) + @property + def all_errors(self) -> list[str | LazyString]: + """Returns all the errors of the form. + + :return: All the errors of the form. + """ + all_errors: list[str | LazyString] = [] + for key in self.errors: + if key != "csrf_token": + all_errors.extend(self.errors[key]) + return all_errors + class RecurringExpenseForm(RecurringItemForm): """The sub-form to add or update the recurring expenses.""" diff --git a/src/accounting/templates/accounting/option/include/form-recurring-item.html b/src/accounting/templates/accounting/option/include/form-recurring-item.html index 7c500a5..acd6548 100644 --- a/src/accounting/templates/accounting/option/include/form-recurring-item.html +++ b/src/accounting/templates/accounting/option/include/form-recurring-item.html @@ -27,12 +27,12 @@ First written: 2023/3/22
-
+
{{ form.account_text|accounting_default }}
{{ form.name.data|accounting_default }}
{{ form.description_template.data|accounting_default }}
-
{% if form.form_errors %}{{ form.form_errors[0] }}{% endif %}
+
{% if form.all_errors %}{{ form.all_errors[0] }}{% endif %}