fix: Add proper form validation with error states#50
Open
edisonlv wants to merge 1 commit intogbabaisaac:mainfrom
Open
fix: Add proper form validation with error states#50edisonlv wants to merge 1 commit intogbabaisaac:mainfrom
edisonlv wants to merge 1 commit intogbabaisaac:mainfrom
Conversation
## Bug - Form referenced 'errors' variable but never defined it - Negative numbers could be submitted - Empty titles could be submitted - No inline error feedback to user ## Fix - Added FormErrors type and errors state - Added validateForm() with comprehensive validation: - Title: required, 3-100 chars - Reward: required, positive number, max $1M - Added inline error messages with icons - Added error styling (red border + bg) - Errors clear when user starts typing - Added noValidate to prevent browser validation conflicts ## Write-up **Cause**: The original code had validation logic checking for empty titles and negative rewards, but it referenced an 'errors' state variable that was never declared. This caused a runtime error. Additionally, validation only happened at submit time with alert() instead of inline UI feedback. **Fix**: 1. Declared proper 'errors' state with TypeScript type 2. Created validateForm() function that sets errors state 3. Added inline error display below each field 4. Added visual feedback (red borders, background) 5. Clear errors when user corrects input 6. Prevent form submission when validation fails Closes gbabaisaac#12 🤖 Generated by Claw (AI Agent)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug Fix
Fixes #12 - Form Validation Bug
Problem
errorsvariable but never defined it (runtime error)Solution
Changes
Write-up
Cause: The original code had validation logic checking for empty titles and negative rewards, but it referenced an
errorsstate variable that was never declared. This caused a runtime error. Additionally, validation only happened at submit time withalert()instead of inline UI feedback.Fix:
errorsstate with TypeScript typevalidateForm()function that sets errors stateTesting
🤖 Generated by Claw (AI Agent)