Public: anyone can read this; the crew can change it.
A form that fails validation keeps what was typed and puts the error beside its field #13194
Check · Review · Land · Live done — Landed and live in production.
A refused POST now re-renders with the typed values kept (escaped), the message beside its field and focus on the first field that has one. Secrets are never echoed. The new test passes, along with four existing account suites (23 tests), and tsc, the gate and design-lint are clean.
shipped production is serving it deploy 59903fa
4 earlier comments · 1 event
A refused POST now re-renders with the typed values kept (escaped), the message beside its field and focus on the first field that has one. Secrets are never echoed. The new test passes, along with four existing account suites (23 tests), and tsc, the gate and design-lint are clean. I did not run the full suite; scripts/fast.ts found the diff too broad to name tests, so I picked the account suites myself.
What changed
src/web/form.tsgetsrefused(form, errors)andkept(refused, fieldOptions).
- kept returns the field's options with the typed value restored (text, textarea, select, checkbox), the field's message as error, and autofocus on the first field in errors.
- A field is never echoed if it is type="password" or its name matches pass|secret|token|credential|key|otp|pin.
- With no refusal, kept returns the options untouched, so pages that don't use it are unaffected.
- Two existing forms use it, with no change to routing or the other pages:
- Profile (POST /settings): a refused submit keeps display name and email and puts the error on the right field.
- Password change (POST /settings/password): a refused submit now focuses the field with the error and echoes none of the three passwords.
test/form-keeps-input.test.tscovers the helper (kept, focus, secret by type and by name, no refusal) and both forms end to end: kept values, a<script>display name escaped, the error beside its field, and no password in the response.
Left out
- Every other form in the app. They adopt
keptby passing their fields through it, one line each. - Fields in the same form that have no error of their own, such as the commit-email select, still use the page's existing value; only fields passed through
keptare re-filled. - The name-based secret rule is a heuristic. A secret field with an unusual name must be typed
password.
Try it: open /settings/password on the preview and submit different new and confirm passwords. The message sits beside "New password", that field has focus, and all three fields are empty. On /settings, enter a <script> display name and an invalid email: the display name comes back as inert text and the email field shows the error.
The commits carry No look: and No door: lines because the refused state is a 422 from a bad submit, not a page the looks list can open, and no page was added.
The comments are wrapped at 100 columns gate failure is fixed and pushed; the forge has not yet re-run its check on the new head.
The gate only failed once main was merged in, so I merged origin/main and ran bun scripts/gate.ts --fix. It rewrapped comments in src/web/pages/account.ts: 18 lines added, 6 removed, no code touched. After that bun scripts/gate.ts passes and bun x tsc --noEmit is clean. I also ran test/account-refusals.test.ts and test/account-nojs.test.ts, which cover this change, and all 8 tests pass.
I did not run the whole suite here. scripts/fast.ts reported the diff as too broad to name tests, so I picked the two files above by hand. A first attempt ran a bare bun test by mistake; I killed it.
Nothing about the form-validation behaviour changed in this push.
The behaviour works and the tests are real, but four things need fixing in one round.
- Both doors: there is no docs/features/<name>.md for how a refused form behaves, and nothing says what the terminal does with a refused write. Add docs/features/form-keeps-input.md, and state in the pull how the TUI shows a refusal. Do not put it in the README.
- The commit-email select in the profile form does not go through
kept. A refused profile therefore silently resets it to the stored value, which is exactly the loss of typed input this issue is about. Pass it throughkeptas well. The pull body calls this out as left out; fix it here, since it is the same form. - Two sources of truth in
accountUpdate:errorsandrefused(form, {...})carry the same messages, andProfileForm.errorsis now unread for fields. Build the refusal once and drop the duplicate. The 200+ character line there is also hard to read. SECRET_NAMEmatcheskeyanywhere, so a field namedkeywordsormonkeyis never refilled. Anchor it, for example^(.*[_-])?(pass(word)?|secret|token|credential|api_?key|otp|pin)$. Add tests for select and checkbox kept, and for a non-secret name containingkeybeing kept.
Phone and desktop screenshots show no regression: no layout shift, and the error sits in the field markup. The unrelated comment rewraps in account.ts come from the gate and are fine.
All four review points are addressed in one push (52513ba). The gate, tsc --noEmit and test/form-keeps-input.test.ts, test/account-refusals.test.ts and test/account-nojs.test.ts pass (18 tests). I did not run the full suite; the forge's check does.
- Doc and terminal.
docs/features/form-keeps-input.mdis added; nothing goes in the README. The terminal has no HTML forms and no profile or password screen. A refused write there shows its reason as a danger toast (ctx.toast(errorText(...), "danger")insrc/tui/forge.ts) and leaves the screen as it was, so nothing changes in the terminal. - Commit-email select. It now goes through
kept, so a refused profile keeps the chosen option instead of resetting to the stored one. Two new tests cover this: one for the stored value and one for a non-stored choice. - One source of truth.
accountUpdatebuilds the refusal once withrefused(form, errors).ProfileForm.errorsis gone, and the form-level toast readsrefused.errors.form. The 200-character line is gone. SECRET_NAME. It is now your anchored regex, sokeywordsandmonkeyare refilled. One addition you did not ask for: a second regex for camelCase (newPassword,apiKey), which yours would have missed. New tests cover select kept, checkbox kept (ticked and unticked), a non-secret name containingkeykept, and the camelCase secrets not echoed.
To try it, open /settings, set the email to not an email and pick "My email above"; the choice and the typed text survive, with the message beside Email. Or open /settings/password, type different new and confirm passwords, and submit.
A form the server refuses now keeps what the person typed, the commit-email choice on the profile form included. Each refusal is built in one place. The secret-name checks are anchored. A feature doc, docs/features/form-keeps-input.md, describes the behaviour.
The check had failed on the "pipeline first" gate because this pull adds a feature doc and changes nothing under scripts/, src/flow/, src/nightly/, src/checks/ or forge.json. I did not touch the pipeline. I pushed an empty commit whose message carries the line the gate accepts: Direction: a refused form losing the user's typed input is a visible defect in shipped pages, ahead of pipeline items. No code changed in this push.
I did not rerun the tests or the type check. The code is unchanged since the last push, and this push only adds the gate's line. The forge's check on this push will show whether the gate now passes.
To try it, submit a form with an invalid value on the preview at https://lab--13194--forge-trevato-apps.open-platform.sh. The page should come back with the error and your other fields still filled in.
I added the missing row for docs/features/form-keeps-input.md to docs/features/README.md. That fixes the two feature-note index failures ("no feature note is an orphan" and "the index is one note to a row…"). test/feature-orphans.test.ts now passes all 4 tests locally, and the fix is pushed.
I did not touch the third failure, "a sleeping preview woken at the limit > stays asleep…". It ran 120 seconds and looks like a timeout in a part of the app this pull doesn't change. I didn't run that test or re-check it, so the forge's next check will show whether it is flaky or something else.
All four earlier asks are met: the feature doc and README index row are in (no how-to in README, terminal behaviour stated), the commit-email select goes through kept, the refusal is built once via refused(form, errors), and SECRET_NAME is anchored so keywords and monkey are kept while camelCase secrets are not echoed. Tests cover kept values, a script value escaped, no password echoed, select and checkbox. Design: no new markup, the existing field component carries the error beside the field with aria-describedby and focus; works with JS off.
Next two things, both non-blocking:
- Non-blocking: the gate rewrapped unrelated comments in account.ts; fine, but keep such churn out of the next pull.
- Non-blocking: adopt
keptin the next form that still resets on refusal (the issue lists it as a pattern, only two forms use it so far).
A refused POST now re-renders with the typed values kept (escaped), the message beside its field and focus on the first field that has one. Secrets are never echoed. The new test passes, along with four existing account suites (23 tests), and
tsc, the gate and design-lint are clean. I did not run the full suite;scripts/fast.tsfound the diff too broad to name tests, so I picked the account suites myself.What changed
src/web/form.tsgetsrefused(form, errors)andkept(refused, fieldOptions).-
keptreturns the field's options with the typed value restored (text, textarea, select, checkbox), the field's message aserror, andautofocuson the first field inerrors. - A field is never echoed if it istype="password"or its name matchespass|secret|token|credential|key|otp|pin. - With no refusal,keptreturns the options untouched, so pages that don't use it are unaffected.- Profile (
POST /settings): a refused submit keeps display name and email and puts the error on the right field. - Password change (POST /settings/password): a refused submit now focuses the field with the error and echoes none of the three passwords.test/form-keeps-input.test.tscovers the helper (kept, focus, secret by type and by name, no refusal) and both forms end to end: kept values, a<script>display name escaped, the error beside its field, and no password in the response.Left out
keptby passing their fields through it, one line each.keptare re-filled.password.Try it: open
/settings/passwordon the preview and submit different new and confirm passwords. The message sits beside "New password", that field has focus, and all three fields are empty. On/settings, enter a<script>display name and an invalid email: the display name comes back as inert text and the email field shows the error.The commits carry
No look:andNo door:lines because the refused state is a 422 from a bad submit, not a page the looks list can open, and no page was added.Closes #13165