Skip to content

fix: validation bugs, simpler public types, and example cleanup - #22

Merged
lucataglia merged 10 commits into
mainfrom
fix/validation-bugs
Jul 29, 2026
Merged

fix: validation bugs, simpler public types, and example cleanup#22
lucataglia merged 10 commits into
mainfrom
fix/validation-bugs

Conversation

@lucataglia

Copy link
Copy Markdown
Collaborator

Cosa

Branch che raccoglie tre filoni di lavoro: correzioni a bug di validazione,
una semplificazione (breaking) dei tipi TypeScript pubblici, e allineamento
degli esempi.

Bugfix di validazione

  • isValidationError: corretto il check sul messaggio nel type guard.
  • check(): ora rispetta lo schema impostato via setSchema (prima usava
    sempre lo schema iniziale).
  • removeAll: ora ri-valida i campi in live-validation dopo la rimozione.

Tipi pubblici (⚠️ breaking)

  • feat!: pulizia e semplificazione dei tipi TypeScript pubblici.
  • Rinominato il type parameter generico ValuesT in tutte le firme
    (FormbitValues resta invariato). Convenzione più concisa e leggibile.

Esempi & manutenzione

  • Fixata la form addable-fields (scriveva/validava path sbagliati: editare un
    friend esistente non funzionava) e f-remove-all (confondeva age/email).
  • Rinominato il tipo FormDataFormValues negli esempi (evita lo shadowing
    del global FormData del browser); import spostati a type-only.
  • Allineati i Provider (initialValues={{}} esplicito), tipi e nomi dei test
    Cypress; documentato perché la fake GET fallisce a random.
  • Bump radicalbit-design-system → 2.19.5 (allineati package.json e yarn.lock
    al pacchetto realmente installato).
  • Regola ESLint per l'indentazione JSX (2 spazi) su root ed example, + reindent
    dei file non conformi.

Luca Tagliabue and others added 10 commits July 29, 2026 15:15
The second OR branch re-checked `path === undefined` instead of
`message === undefined`, so an object with a non-string message and an
undefined path was wrongly accepted as a ValidationError.

Add a dedicated test suite for the guard covering the regression.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
check() validated against the schema captured at hook init, ignoring
setSchema(). Every other validation method already uses schemaRef.current,
so check() now does too, making its behaviour consistent.

Add a regression test asserting check() uses the updated schema.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
removeAll computed `paths` (pathsToValidate + live-validated fields) but
then used only `pathsToValidate` for error teardown and validation, so
fields with active live-validation were skipped — inconsistent with
writeAll, which uses `paths`. Align removeAll to writeAll.

Add a regression test asserting live-validated fields are re-validated.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Rewrite src/types/index.ts for readability and correctness, and export the
useful types from the package entry point so consumers can type their own code.

- Collapse the redundant base types (FormbitRecord, Form, InitialValues) into
  a single FormbitValues type used everywhere.
- Remove the field `isDirty` from PrivateValidateForm options: it was
  destructured and discarded, i.e. dead.
- Simplify SubmitSuccessCallback's writer type to FormState<Omit<Values,
  '__metadata'>>, matching what submitForm actually passes at runtime.
- Reorganise the file into clear sections and tighten the doc comments.
- Re-export FormbitObject, the method/callback/options types and the yup
  re-exports from the package root.

BREAKING CHANGE: the deprecated type aliases are removed (Object, Writer,
SuccessCheckCallback, ErrorCheckCallback, ErrorFn, IsFormValid, IsFormInvalid,
ClearIsDirty, ResetForm, LiveValidationFn, IsDirty), together with the internal
base types FormbitRecord, Form and InitialValues. Use FormbitValues instead.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
`FormData` shadows the browser's global FormData type, which is confusing
in an example meant to teach. Rename it to FormValues across every example
and switch the imports to type-only (`import type` / `import { type ... }`)
for consistency.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The addable-fields example was writing and validating the wrong paths, so
editing an existing friend never worked:
- write targeted `friends[i].key` for both name and surname (→ `.name` / `.surname`)
- validate/error targeted the non-existent `headers[i]` path (→ `friends[i]`)
- the mapped <Friend> had no React key, and `friends?.[i].name` could throw

Also fix f-remove-all, which mixed up `age` and `email`: the loading skeleton
showed an "Email" field with an "Age" placeholder, and it initialized an `email`
value the schema doesn't have — both now consistently use `age`.

Alignment across the examples:
- pass `initialValues={{}}` explicitly on every Provider
- use the single `FormValues` type in e-multiple-steps instead of two divergent
  local `Context` types
- fix copy/pasted Cypress describe/it names
- document why the fake GET randomly fails (and that it makes edit-like flaky)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The three multi-step files were indented with 4 spaces per level (and an
extra offset) instead of the project's 2-space style; d-edit-like's provider
had a stray offset too. ESLint doesn't enforce JSX indentation here and there
is no Prettier, so this went unnoticed. Reindent to 2 spaces and drop the
single-child fragments in StepOne/StepTwo.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
package.json and yarn.lock declared 2.13.1 but node_modules actually had a
newer version installed, so the examples rendered with styles that didn't
match the pinned version. Align all three on 2.19.5, which is the version
that carries the corrected button :focus styling (box-shadow instead of the
old primary color/border on focus).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add react/jsx-indent and react/jsx-indent-props (2 spaces) to both the root
and example eslint configs, so the JSX indentation issues we hit can no longer
slip through. Reindent the few files that weren't conforming.
Rinomina il type parameter generico da Values a T in tutte le firme
dei tipi e nell'implementazione. Convenzione più concisa in stile
Java; FormbitValues resta invariato.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@lucataglia
lucataglia requested a review from rivamarco July 29, 2026 15:22
@lucataglia
lucataglia merged commit 9f19936 into main Jul 29, 2026
4 checks passed
@lucataglia
lucataglia deleted the fix/validation-bugs branch July 29, 2026 15:27
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