Vue 3 Form Provider‑driven Live Validation #2555
Open
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.
Summary
Laravel 12 starter kits have moved from the Inertia useForm helper to the Inertia Form component. Inertia’s Form component does not support Precognition out of the box, making the Laravel 12 Vue starter kits incompatible with Laravel Precognition. This PR adds optional live validation to the Vue 3
, driven by a provider registry. When a provider is registered andprecognitive
is enabled, the form validates on user events and keeps the error bag in sync. This would bridge the gap between Inertia component usage and Laravel Precognition.Key Changes
precognitive
(boolean|object),validateOn
('input'|'change'|'blur'|array),validationTimeout
(ms),provider
(string).validating
andvalidate(name?)
.validateOn
,validationTimeout
, andprecognitive
config (global + per-field opt-in viaprecognitive
ordata-precognitive
attributes).registerLiveValidationProvider()
,getLiveValidationProvider()
,detectInstalledProviders()
.Behavior
precognitive
is truthy (boolean or config object). Per-field opt-in supported viaprecognitive
attribute ordata-precognitive="true"
.provider="<id>"
on theForm
.precognitive
enabled → warn and skip live validation (standard form behavior unchanged).form.setError
.validating
is reactive and exposed.Usage
provider="your-provider-id"
on<Form>
.Provider Requirement
Live validation requires a provider to be registered at runtime.
Provider module shape:
createValidator(requestFactory, initialData)
toSimpleValidationErrors?(errors)
resolveName?(event)
Registry API:
registerLiveValidationProvider({ id, import: () => Promise<ModuleShape> })
Laravel Precognition Integration example
pnpm install laravel-precognition-vue-inertia
)/packages/vue-inertia/src/registerInertiaProvider.ts
):/packages/vue-inertia/src/index.ts
):laravel-precognition-vue-inertia
in the consuming laravel appsapp.ts
or directly in your form SFC. This will auto-register its Vue components/composables):<Form :precognitive="true">
uses Laravel Precognition for live validation unlessprovider
points elsewhere.Types
ValidationEvent = 'input' | 'change' | 'blur'
LiveValidationProps = {
precognitive?,
validateOn?,
validationTimeout?,
provider?}
Backwards Compatibility
precognitive
is truthy.Notes
An alternative approach to solving this problem has been proposed in a PR in the Laravel Precognition github repo, which offloads the precognition functionality fully to Laravel Precognition, using a thin wrapper around the inertia component. Either this PR or the one in Laravel Precognition should be chosen, as they would otherwise conflict with each other.
Testing