fix: add HTMX 422 response handling and missing form name attrs

- Configure HTMX to swap 422 responses so validation errors display
- Add missing name="notes" to egg harvest and product sold forms

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-01 10:40:49 +00:00
parent abf78ec98a
commit 40769f5ce1
3 changed files with 11 additions and 2 deletions

View File

@@ -5,7 +5,7 @@ from __future__ import annotations
from pathlib import Path from pathlib import Path
from fasthtml.common import Beforeware, fast_app from fasthtml.common import Beforeware, Meta, fast_app
from monsterui.all import Theme from monsterui.all import Theme
from starlette.middleware import Middleware from starlette.middleware import Middleware
from starlette.requests import Request from starlette.requests import Request
@@ -123,10 +123,17 @@ def create_app(
# So static_path should be the parent of static_base # So static_path should be the parent of static_base
static_path_for_fasthtml = str(static_base.parent) if static_base.exists() else "." static_path_for_fasthtml = str(static_base.parent) if static_base.exists() else "."
# Configure HTMX to swap 422 responses for validation errors
# Without this, hx-boost ignores non-2xx responses and errors appear to do nothing
htmx_config = Meta(
name="htmx-config",
content='{"responseHandling":[{"code":"204","swap":false},{"code":"[23]..","swap":true},{"code":"422","swap":true},{"code":"[45]..","swap":false,"error":true}]}',
)
# Create FastHTML app with HTMX extensions, MonsterUI theme, and static path # Create FastHTML app with HTMX extensions, MonsterUI theme, and static path
app, rt = fast_app( app, rt = fast_app(
before=beforeware, before=beforeware,
hdrs=Theme.slate.headers(), # Dark industrial theme hdrs=(*Theme.slate.headers(), htmx_config), # Dark industrial theme + HTMX config
exts=["head-support", "preload"], exts=["head-support", "preload"],
static_path=static_path_for_fasthtml, static_path=static_path_for_fasthtml,
middleware=[Middleware(StaticCacheMiddleware)], middleware=[Middleware(StaticCacheMiddleware)],

View File

@@ -160,6 +160,7 @@ def harvest_form(
LabelTextArea( LabelTextArea(
"Notes", "Notes",
id="notes", id="notes",
name="notes",
placeholder="Optional notes", placeholder="Optional notes",
), ),
# Hidden nonce for idempotency # Hidden nonce for idempotency

View File

@@ -99,6 +99,7 @@ def product_sold_form(
LabelTextArea( LabelTextArea(
"Notes", "Notes",
id="notes", id="notes",
name="notes",
placeholder="Optional notes", placeholder="Optional notes",
), ),
# Hidden nonce for idempotency # Hidden nonce for idempotency