main ← fix/form-template-upload-required-validation
opened 06:23PM - 23 Mar 26 UTC
The `required: true` validation on upload fields in form templates was not being… enforced. Users could submit forms without attaching any file even when the upload field was marked as required.
The root cause is that the upload field used a `<input type="hidden">` to store its value. Hidden inputs are excluded from the browser's constraint validation API — `form.checkValidity()` skips them entirely. All other form template field types (input, textarea, dropdown, etc.) use visible form elements where the native `required` attribute works.
The fix changes the hidden input to a visually-hidden `<input type="text">` so that native constraint validation applies. The input is positioned off-screen via CSS and made non-interactive with `tabindex="-1"` and `aria-hidden="true"`. It is also placed as the last child in the container so the validation error message (inserted via `insertAdjacentElement("afterend")`) renders in a visible location.
A synthetic `input` event is dispatched after upload completion so the validation error clears once a file is attached.
https://meta.discourse.org/t/398972