fix: improve cohort form validation for empty/placeholder values
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user