This is an automated email from the ASF dual-hosted git repository.
sbp pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tooling-trusted-releases.git
The following commit(s) were added to refs/heads/main by this push:
new 17871a2 Highlight labels when a form field has an error
17871a2 is described below
commit 17871a21f86fd0e6bbce3141db3fbe0765cf8ca5
Author: Sean B. Palmer <[email protected]>
AuthorDate: Fri Nov 7 15:44:28 2025 +0000
Highlight labels when a form field has an error
---
atr/blueprints/post.py | 5 ++++-
atr/form.py | 15 ++++++++++++++-
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/atr/blueprints/post.py b/atr/blueprints/post.py
index 635b50c..acbce1b 100644
--- a/atr/blueprints/post.py
+++ b/atr/blueprints/post.py
@@ -161,7 +161,10 @@ def form(
plural = len(errors) > 1
summary = f"Please fix the following issue{'s' if plural else
''}:"
ul = htm.Block(htm.ul, classes=".mt-2.mb-0")
- for _name, flash_datum in flash_data.items():
+ for i, flash_datum in enumerate(flash_data.values()):
+ if i > 9:
+ ul.li["And more, not shown here..."]
+ break
ul.li[htm.strong[flash_datum["label"]], ": ",
flash_datum["msg"]]
summary = f"{summary}\n{ul.collect()}"
diff --git a/atr/form.py b/atr/form.py
index 8d5ea28..6c5c375 100644
--- a/atr/form.py
+++ b/atr/form.py
@@ -18,6 +18,7 @@
from __future__ import annotations
import enum
+import json
import types
from typing import TYPE_CHECKING, Annotated, Any, Final, Literal, get_args,
get_origin
@@ -127,6 +128,16 @@ async def render_columns(
if action is None:
action = quart.request.path
+ flash_error_data: dict[str, Any] = {}
+ flashed_error_messages =
quart.get_flashed_messages(category_filter=["form-error-data"])
+ if flashed_error_messages:
+ try:
+ first_message = flashed_error_messages[0]
+ if isinstance(first_message, str):
+ flash_error_data = json.loads(first_message)
+ except (json.JSONDecodeError, IndexError):
+ pass
+
label_classes = "col-sm-3 col-form-label text-sm-end"
field_rows: list[htm.Element] = []
@@ -156,7 +167,9 @@ async def render_columns(
label_text = field_info.description or field_name.replace("_", "
").title()
is_required = field_info.is_required()
- label_elem = htpy.label(for_=field_name,
class_=label_classes)[label_text]
+ has_flash_error = field_name in flash_error_data
+ label_classes_with_error = f"{label_classes} text-danger" if
has_flash_error else label_classes
+ label_elem = htpy.label(for_=field_name,
class_=label_classes_with_error)[label_text]
widget_elem = _render_widget(
field_name=field_name,
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]