Form validation errors persist after the subject fixes the failing field, until the next submit
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- react, typescript
- Lĩnh vực
- frontend
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Open any form instrument that has a required field, e.g. in the playground or through
apps/web→ Instruments → render. - Leave the required field empty and press submit.
- Fill in the field with a valid value.
- The field error and
form-error-summarystay 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'serrorsstate. They are set byhandleErrorand cleared only byreset()(successful submit or the reset button), a language change, or the nexthandleSubmit. Field components receivesetError, but none of the scalar fields call it when their value changes. revalidateOnBlurexists, but it has two problems.revalidate()only callshandleErrorwhen the parse fails. A parse that now succeeds never clearserrors/rootErrors, so the last error stays even with this option on. It also routes throughhandleError, which callsonError, so a blur would count as a failed submit in our hook (below).
packages/react-core
FormContent(src/components/FormContent/FormContent.tsx) does not passrevalidateOnBlur.- The summary is shown when
failedSubmitCount > 0. That count comes fromuseFocusFirstInvalidField(src/hooks/useFocusFirstInvalidField.ts) and is reset only byonSuccessfulSubmit. 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 raisefailedSubmitCount. 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
-
Upstream (libui): after a failed submit, revalidate when values change (or on blur), and set
errors/rootErrorsfrom the result, including clearing them when the parse succeeds. Revalidation must not callonError, 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. -
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 fromfailedSubmitCount. Keep the scroll-and-focus effect tied to submit attempts only. -
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.tsalready exposeserrorSummary).
Scope notes
- This affects every form instrument in
apps/web,apps/gatewayandapps/playground, because they all render throughFormContent. Series instruments are affected too, since each form step is aFormContent. - Cross-field (
superRefine/root) errors should follow the same rule: clear them once the whole object parses.
- Ngôn ngữ chính
- TypeScript
- Star
- 119
- Fork
- 19
- Merge trung bình
- 1 ngày 18 giờ
- Pull request đã merge (30 ngày)
- 60
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của DouglasNeuroInformatics/OpenDataCapture
-
A docs change can fail pnpm check, because outreach lint and gen:types both write .astro/ at onceCó thể đã có người làm @2389400626lh-ops đã nhận hôm nay. Đang mởArea: Infrastructure Area: Outreach Bug Difficulty: Low Good First Issue Priority: Low
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
DouglasNeuroInformatics/OpenDataCapture#1956 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Area: Infrastructure Chore Difficulty: Low Priority: Low
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
DouglasNeuroInformatics/OpenDataCapture#1948 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
apps/web preview overwrites newly built dist/index.html with stale dist/index.html.bak across buildsĐang mởArea: Infrastructure Area: Web Bug Difficulty: Low Priority: Medium
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
DouglasNeuroInformatics/OpenDataCapture#1938 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Area: API Bug Difficulty: Low Priority: Low
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
DouglasNeuroInformatics/OpenDataCapture#1937 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Area: Infrastructure Bug Difficulty: Low Priority: Medium Security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
DouglasNeuroInformatics/OpenDataCapture#1916 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của DouglasNeuroInformatics/OpenDataCapture
Issue tương tự
-
Resources: New templates of Beijing SubwayCó thể đã có người làm @rmt-svc đã nhận hôm nay. Đang mởresources
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
railmapgen/rmg-templates#2726 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
needs triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
homarr-labs/homarr#7729 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Buzzpy/Dev-Encyclopedia#218 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
prio:low status:done type:content
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
davidsneighbour/samui-samui.de#1925 ·