-
Notifications
You must be signed in to change notification settings - Fork 527
Support for Precognition in <Form>
component
#2619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
pascalbaljet
wants to merge
46
commits into
master
Choose a base branch
from
form-precognition
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
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.
This PR brings support for Laravel Precognition to the
<Form>
component. The goal is to provide complete feature parity with the Laravel Precognition library. We decided to build this directly into Inertia for three reasons:laravel-precognition
an optional peer dependency of Inertia.useForm()
inlaravel-precognition
is manageable, patching the<Form>
component would quickly become messy and difficult to unit test. Inertia already has an extensive Playwright setup.Here's how you can use it in Vue:
In addition to
invalid()
, there's alsovalid()
, which returns true only when the field has been validated and contains no errors.You may configure the debounce timeout (defaults to 1500ms) and include files with the
validateFiles
andvalidateTimeout
props.A
touch()
method is available to mark fields for validation, and atouched()
method checks if fields have been touched. The existingreset()
method has been updated to also reset the touched state of a field.The
defaults()
method also has been updated to sets the current state of the data on the internal validator, ensuring it only triggers validation when it changes again.Lastly, you may pass an object of options to
validate()
.Alternatively, you may pass an
only
option to the options object, which can be a string or array of fields.The
onBeforeValidation
andonException
options allow you to hook into the validation lifecycle.onBeforeValidation
receives the new and old request data, and returning false will prevent the validation request.onException
handles non-422 errors that occur during validation.Laravel validation errors are typically arrays of messages per field. The Inertia middleware automatically simplifies these to just the first error for each field. However, the middleware doesn't run on
422
responses, so the<Form>
component handles this transformation by default. Setsimple-validation-errors
tofalse
to keep the original array format.