Repository navigation
feat(session): flash field errors without a validation exception - #105
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
An app can need to attach an error to a form field after validation, for example "this email is already registered". The
@inputErrorEdge tag and the Inertia adapter read these errors from theinputErrorsBagflash key. No public method writes to it:flashErrors()writes toerrorsBag, which@errorreads, not@inputErroror Inertia.flashValidationErrors()needs a VineJSValidationException. It also adds a summary toerrorsBagand flashes the request input.So apps write the internal key by hand:
Solution
Add
session.flashInputErrors():flashValidationErrors()writes.errorsBagand it does not flash the request input.The name follows
inputErrorsBagand@inputError.