Form validation errors persist after the subject fixes the failing field, until the next submit

Aperta
#1,944 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
react, typescript
Ambito
frontend

Direzione di ricerca

The fix spans two packages. Start with Form.js in the vendored libui 6.20.0 build, where revalidate() only sets errors on a failed parse, then read FormContent.tsx and useFocusFirstInvalidField.ts in react-core to see why the summary depends on failedSubmitCount. Run FormContent.test.tsx first; done means fixing a field clears its error and the summary without a submit, with no focus or scroll change, and the e2e errorSummary check in testing/src/pages/_app/instruments/render/$id.page.ts passes.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Area: Shared Bug Difficulty: Medium Priority: Medium Upstream

Problem

When a subject submits a form instrument with invalid or missing answers, the failing fields show an error and the summary under the button says "Some fields are incomplete or invalid…". If the subject then fixes those fields, every error stays on screen until they press submit again. The form looks broken even after the subject has fixed it, and they get no sign that their fix worked.

Expected: once the subject changes a failing field so that it is valid, that field's error goes away. When no errors remain, the summary goes away too. Both should happen before the next press of the submit/next button.

Steps to reproduce

  1. Open any form instrument that has a required field, e.g. in the playground or through apps/web → Instruments → render.
  2. Leave the required field empty and press submit.
  3. Fill in the field with a valid value.
  4. The field error and form-error-summary stay visible until submit is pressed again.

Cause

There are two layers, and both only clear on submit.

libui Form (@douglasneuroinformatics/[email protected], dist/components/Form/Form.js)

  • Field errors live in Form's errors state. They are set by handleError and cleared only by reset() (successful submit or the reset button), a language change, or the next handleSubmit. Field components receive setError, but none of the scalar fields call it when their value changes.
  • revalidateOnBlur exists, but it has two problems. revalidate() only calls handleError when the parse fails. A parse that now succeeds never clears errors/rootErrors, so the last error stays even with this option on. It also routes through handleError, which calls onError, so a blur would count as a failed submit in our hook (below).

packages/react-core

  • FormContent (src/components/FormContent/FormContent.tsx) does not pass revalidateOnBlur.
  • The summary is shown when failedSubmitCount > 0. That count comes from useFocusFirstInvalidField (src/hooks/useFocusFirstInvalidField.ts) and is reset only by onSuccessfulSubmit. So the summary cannot go away until a submit succeeds, whatever libui does.
  • If we just turned on revalidateOnBlur, each blur on a still-invalid form would raise failedSubmitCount. That would scroll the page and move focus to the first invalid field while the subject is still working through the form.

The current test should clear the error summary once the corrected answers submit (FormContent.test.tsx) covers only the clear-on-submit path.

Proposed fix

  1. Upstream (libui): after a failed submit, revalidate when values change (or on blur), and set errors/rootErrors from the result, including clearing them when the parse succeeds. Revalidation must not call onError, or it must let the caller tell a revalidation apart from a failed submit. A simpler alternative is to clear just that field's error when its value changes.

  2. react-core: take the libui version with that fix and enable it in FormContent. Then decide whether to show the summary from whether any errors remain, not from failedSubmitCount. Keep the scroll-and-focus effect tied to submit attempts only.

  3. Add unit tests:

    • fixing the only failing field clears its error and the summary without a submit;
    • fixing one of two failing fields clears only that field's error;
    • revalidation does not move focus or scroll.

    Also extend the e2e render-page check (testing/src/pages/_app/instruments/render/$id.page.ts already exposes errorSummary).

Scope notes

  • This affects every form instrument in apps/web, apps/gateway and apps/playground, because they all render through FormContent. Series instruments are affected too, since each form step is a FormContent.
  • Cross-field (superRefine/root) errors should follow the same rule: clear them once the whole object parses.
Lingua principale
TypeScript
Stelle
119
Fork
19
Merge medio
1g 18h
PR unite (30g)
60

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di DouglasNeuroInformatics/OpenDataCapture

Tutte le issue di DouglasNeuroInformatics/OpenDataCapture

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.