-
Notifications
You must be signed in to change notification settings - Fork 538
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
Conversation
This reverts commit 2d2307a.
|
Hello @pascalbaljet 👋 Sorry for the hop-in, looks like this PR is solving frontend form validation issue we (and others) have while using complex form with Inertia. Do you know when this would land production ? 🙏 |
|
Converted back to draft as I want to refactor the integration to be based on PR #2684.
I can't give an exact date, but probably in 2-3 weeks. |
|
I'm closing this one in favor of #2700. |
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 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
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. Setsimple-validation-errorstofalseto keep the original array format.