From 680227f53f1469269fd1f9ce81c556e00a295556 Mon Sep 17 00:00:00 2001 From: Petru Paler Date: Thu, 1 Jan 2026 13:32:14 +0000 Subject: [PATCH] fix: improve cohort form validation for empty/placeholder values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The validation now checks that select values are in the allowed set, not just non-empty. This catches cases where browsers send placeholder text (e.g., "Select location...") instead of empty string for disabled options. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- src/animaltrack/web/routes/actions.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/animaltrack/web/routes/actions.py b/src/animaltrack/web/routes/actions.py index ea6c72e..b40f929 100644 --- a/src/animaltrack/web/routes/actions.py +++ b/src/animaltrack/web/routes/actions.py @@ -145,14 +145,15 @@ async def animal_cohort(request: Request): except ValueError: return _render_cohort_error(locations, species_list, "Count must be a valid number", form) - # Validate required fields - if not species: + # Validate required fields - check for empty or placeholder values + # Note: disabled placeholder options may send their text instead of empty value + if not species or species not in ("duck", "goose"): return _render_cohort_error(locations, species_list, "Please select a species", form) - if not location_id: + if not location_id or len(location_id) != 26: return _render_cohort_error(locations, species_list, "Please select a location", form) - if not life_stage: + if not life_stage or life_stage not in ("hatchling", "juvenile", "subadult", "adult"): return _render_cohort_error(locations, species_list, "Please select a life stage", form) - if not origin: + if not origin or origin not in ("hatched", "purchased", "rescued", "unknown"): return _render_cohort_error(locations, species_list, "Please select an origin", form) # Create payload