From c24d09fdd8619cc684fcf1bd961dc3f8128dd6a8 Mon Sep 17 00:00:00 2001 From: Eden Kirin Date: Sun, 7 Apr 2024 00:50:30 +0200 Subject: [PATCH] Toast --- project/main/templates/main/base/base.html | 1 + .../main/templates/main/components/toast.html | 9 ++++ .../main/templates/main/form_validation.html | 43 +++++++++++++------ .../main/form_validation_content.html | 7 +++ project/main/views/form_validation.py | 5 +++ 5 files changed, 51 insertions(+), 14 deletions(-) create mode 100644 project/main/templates/main/components/toast.html diff --git a/project/main/templates/main/base/base.html b/project/main/templates/main/base/base.html index 99fad34..690ea44 100644 --- a/project/main/templates/main/base/base.html +++ b/project/main/templates/main/base/base.html @@ -5,6 +5,7 @@ + {{ title or "Django-html demo" }} diff --git a/project/main/templates/main/components/toast.html b/project/main/templates/main/components/toast.html new file mode 100644 index 0000000..eb508c3 --- /dev/null +++ b/project/main/templates/main/components/toast.html @@ -0,0 +1,9 @@ +{% macro toast(title, id) %} +
+
+
+ {{ title }} +
+
+
+{% endmacro %} diff --git a/project/main/templates/main/form_validation.html b/project/main/templates/main/form_validation.html index f6d8c83..bb6082a 100644 --- a/project/main/templates/main/form_validation.html +++ b/project/main/templates/main/form_validation.html @@ -1,19 +1,34 @@ {% extends "main/base/layout.html" %} +{% from "main/components/toast.html" import toast %} {% block content %} -
-
- {% include "main/form_validation_content.html" %} -
- -
-
-
+
+
+ {% include "main/form_validation_content.html" %} +
+ +
+
+
+ + {{ toast(title="Form validated and saved successfully", id="toast-success") }} + + + {% endblock %} diff --git a/project/main/templates/main/form_validation_content.html b/project/main/templates/main/form_validation_content.html index f0cd0b0..15ed66a 100644 --- a/project/main/templates/main/form_validation_content.html +++ b/project/main/templates/main/form_validation_content.html @@ -57,3 +57,10 @@ {% endif %} + + +{% if validation.is_valid %} + +{% endif %} diff --git a/project/main/views/form_validation.py b/project/main/views/form_validation.py index a462d72..8c0d119 100644 --- a/project/main/views/form_validation.py +++ b/project/main/views/form_validation.py @@ -11,6 +11,7 @@ from project.main.views.demo_view_base import DemoViewBase @dataclass class Validation: validated: bool = False + is_valid: bool = False name: Optional[str] = None consent: Optional[bool] = None @@ -57,6 +58,10 @@ class FormValidationView(DemoViewBase): if not validation.consent: validation.consent_error = "You should consent" + validation.is_valid = not ( + validation.name_error or validation.age_error or validation.consent_error + ) + return render( context={ "validation": validation,