Skip to content

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:

  1. Fix the value — type a valid value, validation succeeds, they can leave
  2. Press Esc — reverts to the last known good value

While locked:

KeyBehavior
Type a characterReplace selected text, continue editing
Enter / Tab / arrowsAttempt to leave → validation runs again → locked if still invalid
EscRevert to last good value, exit edit mode, clear error
Ctrl+SValidation 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 validationSave validation
WhenCursor leaves fieldUser presses Ctrl+S
ScopeSingle fieldAll changed fields
Endpoint/validate/{field_id}/{value}/screen/.../save
AutofillYesNo
Field lockYesNo (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.