Skip to content

feat(session): flash field errors without a validation exception - #105

Merged
thetutlage merged 2 commits into
8.xfrom
feat/flash-input-errors
Oct 23, 2026
Merged

thetutlage merged 2 commits into
8.xfrom
feat/flash-input-errors

Conversation

@RomainLanz

Copy link
Copy Markdown
Member

Problem

An app can need to attach an error to a form field after validation, for example "this email is already registered". The @inputError Edge tag and the Inertia adapter read these errors from the inputErrorsBag flash key. No public method writes to it:

  • flashErrors() writes to errorsBag, which @error reads, not @inputError or Inertia.
  • flashValidationErrors() needs a VineJS ValidationException. It also adds a summary to errorsBag and flashes the request input.

So apps write the internal key by hand:

session.flash('inputErrorsBag', { email: ['Email is taken'] })

Solution

Add session.flashInputErrors():

session.flashInputErrors({ email: 'Email is taken' })
  • A message can be a string or an array of strings. The bag always stores an array, which is the format that flashValidationErrors() writes.
  • The messages are added to the messages already flashed for the same field. They do not replace them.
  • It does not write to errorsBag and it does not flash the request input.

The name follows inputErrorsBag and @inputError.

Business errors that belong to a form field had no public API. Apps
wrote the internal "inputErrorsBag" flash key by hand, a format shared
by the "@InputError" Edge tag and the Inertia adapter, and had to
wrap each message in an array themselves.

flashInputErrors() takes messages keyed by field, accepts a string or
an array, and appends them to the messages already flashed for the
field. Unlike flashValidationErrors, it adds no summary to errorsBag
and does not flash the request input.
A field named like an Object.prototype member, such as "constructor",
read the inherited function from the accumulator and concat threw a
TypeError. The accumulator now has a null prototype.
@thetutlage
thetutlage merged commit b97d213 into 8.x Oct 23, 2026
14 checks passed
@thetutlage
thetutlage deleted the feat/flash-input-errors branch October 23, 2026 03:47
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.

2 participants