Skip to content

Conversation

@alexwarren
Copy link
Contributor

Implements #146

claude and others added 5 commits January 14, 2026 21:18
Implement validation checking before section/passage navigation:
- Add areInputsValid() function to check HTML5 validation constraints
- Add updateLinkStates() to dynamically enable/disable links based on validation
- Add setupInputValidation() to attach event listeners to input elements
- Prevent link navigation when inputs are invalid
- Add visual feedback with CSS classes for invalid inputs and disabled links
- Add validation attributes (required, minlength, maxlength) to gameshow and coffeeshop examples

Visual styling:
- Invalid inputs show red border and shadow
- Valid inputs show green border
- Links disabled by validation appear grayed out with reduced opacity
- Proper accessibility attributes (aria-disabled) added to disabled links

This allows story authors to use standard HTML validation attributes
(required, minlength, maxlength, pattern, etc.) on input fields, and
the runtime will automatically prevent navigation until all inputs are valid.
Tests (runtime/src/squiffy.runtime.test.ts):
- Test that required inputs disable links when empty
- Test that links enable when required inputs are filled
- Test that passage links are also validated
- Test that multiple inputs must all be valid
- Test that validation resets when moving to new section
- Test that disabled inputs are ignored in validation
- Test that clearing input re-disables links

Documentation (site/src/content/docs/basic-concepts.mdx):
- Add comprehensive "User Input" section explaining data-attribute
- Document HTML5 validation attributes (required, minlength, etc.)
- Provide interactive examples showing input capture
- Demonstrate validation in action with multiple input types
- Show select and textarea examples

All tests pass (71 passed, 6 skipped, 77 total)
All packages build successfully
Move validation code from squiffy.runtime.ts to inputValidation.ts:
- areInputsValid(): check if all inputs pass HTML5 validation
- updateLinkStates(): enable/disable links based on validation state
- setupInputValidation(): attach event listeners to inputs

This keeps the main runtime file focused while the validation logic
is now self-contained in its own module with clear documentation.
The validation logic already included select elements in the selector,
but the newSection() function was not saving select values when
navigating to a new section. This adds handling for select elements
alongside the existing input and textarea handling.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@alexwarren alexwarren merged commit 9409096 into textadventures:main Jan 15, 2026
5 checks passed
@alexwarren alexwarren deleted the claude/add-input-validation-ZXo2G branch January 15, 2026 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants