Validation
Summary
How 2Wee validates field values — three layers, field locking, and the distinction between blur and save validation.
How it works
Validation layers
When a user leaves a field, validations run in order:
Layer 1: Type-Specific Parsing (synchronous, client-side)
│ Date shorthand → full date
│ Time shorthand → full time
│ Fails? → Stay in edit mode, show parse error
│
▼
Layer 2: Local Validation Rules (synchronous, client-side)
│ Pattern (regex), Required, Min/Max length, Numeric bounds
│ Fails? → Stay in edit mode, show validation error, select all
│
▼
Layer 3: Server-Side Validation (asynchronous, network call)
│ Lookup blur validation: GET /validate/{field_id}/{value}
│ Succeeds? → Apply autofill values to related fields
│ Fails? → Navigate back to field, enter edit mode, select all
│ Network error? → Warning only, don't block user
│
▼
(User can leave the field)Layers 1 and 2 are synchronous (immediate). Layer 3 is asynchronous — the cursor moves to the next field, then the server responds. If the server rejects the value, the cursor bounces back.
Field locking
When any validation fails, the user cannot leave the field. They must either:
- Fix the value — type a valid value, validation succeeds, they can leave
- Press
Esc— reverts to the last known good value
While locked:
| Key | Behavior |
|---|---|
| Type a character | Replace selected text, continue editing |
| Enter / Tab / arrows | Attempt to leave → validation runs again → locked if still invalid |
| Esc | Revert to last good value, exit edit mode, clear error |
| Ctrl+S | Validation runs first — if it fails, stays locked |
The revert value
The revert value is always the last known good value — not the rejected value. Esc always returns to a safe state.
Blur vs save validation
| Blur validation | Save validation | |
|---|---|---|
| When | Cursor leaves field | User presses Ctrl+S |
| Scope | Single field | All changed fields |
| Endpoint | /validate/{field_id}/{value} | /screen/.../save |
| Autofill | Yes | No |
| Field lock | Yes | No (error shown, user decides) |
Both are necessary. Blur validation gives instant feedback. Save validation is the final gate for cross-field rules and business logic.
Network error handling
If the validate endpoint is unreachable, the client shows a warning but does not block the user. A flaky network should not prevent editing. The save endpoint validates everything again.