-
Notifications
You must be signed in to change notification settings - Fork 537
Support for Precognition in <Form> component
#2700
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
Open
pascalbaljet
wants to merge
102
commits into
precognition-useform
Choose a base branch
from
precognition-merge
base: precognition-useform
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.
Open
+2,848
−48
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 replaces #2619 and is now based on the work done in PR #2684.
This PR brings support for Laravel Precognition to the
<Form>component. We decided to build this directly into Inertia (instead of the Precognition library) for two reasons:useForm()inlaravel-precognitionis 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
validateFilesandvalidateTimeoutprops.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 callreset()on the underlying validator.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
onlyoption to the options object, which can be a string or array of fields.The
onBeforeoption allow you to hook into the validation lifecycle.onBeforereceives the new and old request data, and returning false will prevent the validation request.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
422responses, so the<Form>component handles this transformation by default. Usewith-all-errorsto keep the original array format.