Skip to content

fix(forms): clearing an optional text field on edit now persists - #40

Merged
simonorzel26 merged 1 commit into
mainfrom
fix/schema-form-optional-clear
Jul 29, 2026
Merged

fix(forms): clearing an optional text field on edit now persists#40
simonorzel26 merged 1 commit into
mainfrom
fix/schema-form-optional-clear

Conversation

@simonorzel26

Copy link
Copy Markdown
Contributor

The bug (live on prod, regression from #37)

#37 fixed "optional empty fields block create submit" by stripping "" → undefined for every optional field. That over-reached: for a plain optional string, "" is a legitimate value — the user clearing the field. Stripping it meant the cleared key reached drizzle .set() as undefined (skipped), so the old value silently survived a save the UI reported as successful.

Repro on current prod: edit any record in /de/risks (or suppliers, policies, kpis, patches…), clear an optional text field like description, save, reload — the old text comes back. Found by 4 independent review finders converging on the same trace: CrudPage onUpdate → *UpdateSchema.partial() → drizzle .set().

The fix

Strip "" only for fields whose own validator rejects "" (uuid FK, date, number, url, enum) — those need it to submit. Keep "" for plain optional text so clears persist. The strip set is derived per field via fieldSchema.safeParse(""), so it self-adjusts as schemas change; no hand-maintained list.

Verified

Against asset/supplier/risk validators (script in the commit):

  • Strip (submit still works): quantity, customerCompanyId, lastPatchDate, residualLikelihood, booleans…
  • Keep (clearing now persists): description, owner, hostname, contactName, category, riskOwner

Typecheck clean. Regression e2e test (edit → clear → reload → assert empty) is added on the e2e branch to guard it going forward.

Not merging without your go.

🤖 Generated with Claude Code

https://claude.ai/code/session_01De1NY1HDUJkkwetVKTbYtH

The #37 fix stripped "" to undefined for EVERY optional field so an
untouched optional uuid/date default would stop blocking submit. That
over-reached: for a plain optional string, "" is a legitimate value (the
user clearing the field), and stripping it meant the cleared key reached
drizzle .set() as undefined, which is skipped, so the old value silently
survived a save the UI reported as successful (CrudPage edit forms:
suppliers, policies, kpis, patches, changes, improvements, exercises,
audits, reviews, and supplier-portal profile).

Now "" is stripped only for fields whose own validator rejects it
(uuid/date/number/url/enum), keeping it for plain text so clears persist.
The strip set is derived per-field via fieldSchema.safeParse(""), so it
stays correct as schemas evolve — no hand-maintained field list.

Verified against asset/supplier/risk validators: numeric/boolean/date/FK
fields strip (original create-submit bug stays fixed), plain text fields
(description, owner, hostname, contactName, ...) keep "" (regression fixed).
@simonorzel26
simonorzel26 merged commit 8b04df2 into main Jul 29, 2026
3 checks passed
@simonorzel26
simonorzel26 deleted the fix/schema-form-optional-clear branch July 29, 2026 09:58
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.

1 participant