MCPcopy Create free account
hub / github.com/adonisjs/session / flashInputErrors

Method flashInputErrors

src/session.ts:456–471  ·  view source on GitHub ↗

* Flashes error messages for form fields to the inputErrorsBag, the same * bag "flashValidationErrors" fills. The "@inputError" tag and the Inertia * adapter read them like validation errors. Messages are appended to the * ones already flashed for a field. * * @param messages - Error

(messages: Record<string, string | string[]>)

Source from the content-addressed store, hash-verified

454 * session.flashInputErrors({ email: 'This email is already registered' })
455 */
456 flashInputErrors(messages: Record<string, string | string[]>) {
457 /**
458 * Null prototype, so a field named like an Object.prototype member
459 * (e.g. "constructor") does not read an inherited value.
460 */
461 const inputErrors: Record<string, string[]> = Object.assign(
462 Object.create(null),
463 this.#getFlashStore('write').get('inputErrorsBag', {})
464 )
465
466 for (const [field, fieldMessages] of Object.entries(messages)) {
467 inputErrors[field] = (inputErrors[field] ?? []).concat(fieldMessages)
468 }
469
470 this.flash('inputErrorsBag', inputErrors)
471 }
472
473 /**
474 * Flashes validation error messages. Make sure the error is an instance of VineJS ValidationException.

Callers 1

session.spec.tsFile · 0.80

Calls 4

#getFlashStoreMethod · 0.95
flashMethod · 0.95
createMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected