Skip to content

feat: add Form and Field components - #91

Open
sanketpatel32 wants to merge 2 commits into
streamich:masterfrom
sanketpatel32:devin/issue-25-forms
Open

sanketpatel32 wants to merge 2 commits into
streamich:masterfrom
sanketpatel32:devin/issue-25-forms

Conversation

@sanketpatel32

@sanketpatel32 sanketpatel32 commented Nov 28, 2026 •

Copy link
Copy Markdown

Fixes #25

What

Form state management components in libreact's render-prop style, following the formik / react-final-form / redux-form prior art referenced in the issue:

  • <Form> — tracks values, errors, touched, submitting, and submitCount. Exposes setValue / setTouched / setError / validate / submit / reset / field through its render prop. Supports form-level validation and async onSubmit (keeps submitting true until the returned promise settles).
  • <Field> — consumes the surrounding form through context and gives each input {input, meta} render props: input spreads directly onto the element (name, value, onChange, onBlur), meta carries error and touched for validation feedback. Per-field validators registered through the validate prop run before every submit.

Validation behavior

  • submit() runs all field-level validators plus the form-level validate prop (form-level errors merge over field-level ones), marks every field touched, and only calls onSubmit when no errors exist.
  • reset() restores init values and clears errors and touched state.

Verification

  • 8 new jest client tests covering value tracking, touched-on-blur, blocked submission on validation failure, successful submission values, form-level validation, reset, and async submitting state — all pass.
  • New SSR test file passes; renderToStaticMarkup output verified.
  • Full suite: 28/28 test suites, 161/161 tests pass; tsc build clean.
  • Docs added (docs/en/Form.md) with usage example, registered in SUMMARY.md and README.md following the repo's documentation pattern.

Render-prop form state management per issue streamich#25: Form tracks values,
errors, touched state, and the submission lifecycle; Field wires inputs
into the surrounding form through context with per-field validation.

Assisted-by: Devin:claude-opus-5.5
Assisted-by: Devin:claude-opus-5.5

This branch has not been deployed

No deployments
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.

Forms

1 participant