Hidden Field Guard

When a conditional form section is hidden, it names the fields still filled in there, so old values don't ride along unseen.

StopsHidden field still submitted old value

Installation

pnpm dlx shadcn@latest add https://bollard-ui.vercel.app/r/hidden-field-guard.json

The files land in your project. They're yours to edit.

What it catches

  • Values left in a section the user has hidden
  • Whether those values will still be submitted
  • Clearing that bypasses React state: it fires real input events instead

Props

HiddenFieldGuard props
PropTypeDefault
hidden* (required)

Whether the section is currently hidden (toggle off, another tab or step selected).

boolean—
label* (required)

The section's name, e.g. "Shipping address".

string—
hiddenValues

What happens to hidden values on submit. `submitted`: they're still sent. `discarded`: the section is disabled, so the browser leaves them out.

"submitted" | "discarded""submitted"
onClear

Called after Clear with the names of the fields that were emptied.

(names: string[]) => void—
message

Templates: `{label}`, `{count}` and `{fields}` ("3 filled fields") are filled in.

string"{label} is hidden but still has {fields}."
submittedText

Detail line. `{names}` is filled in.

string"{names} will still be submitted."
discardedText

Shown when hidden values will be dropped on submit.

string"{names} won't be sent while it's hidden."
clearedText

Shown after the values are cleared.

string"Cleared {fields} from {label}."
clearLabel

Clear button text.

string"Clear them"
keepLabel

Keep button text.

string"Keep"
undoLabel

Undo button text.

string"Undo"

* required. Also accepts the native props of <div> (className, aria-*, data-*…), passed through to it.

Accessibility

  • Banner is a labelled region inside a polite live region
  • Field names come from the field's label, aria-label, placeholder or name
  • Keep, Clear and Undo are buttons; icons are aria-hidden

Only what the source does. Test with your own screen reader and content before shipping.

Limitations

  • Only sees native inputs inside the section's DOM; custom widgets that keep values elsewhere are missed
  • Submitted vs dropped depends on the hiddenValues/submitted setting you pass, not on inspecting your submit code

What it stops

Hidden field still submitted old value

Also known as

conditional fields · hidden fields · show hide · react hook form · shouldUnregister · form state · toggle section

Dependencies

Pairs well with