News

Inertia 2.3 Adds Precognition Support

Published Updated
Inertia 2.3 Adds Precognition Support image

Inertia v2.3 was released, adding Laravel Precognition support to the Form component and useForm() out of the box. This update makes it super simple to start validating forms on the frontend using your Laravel validation rules.

No additional packages are needed anymore. Laravel Precognition provides live validation (among other things) for your frontend using your backend validation rules. It hits your route's middleware and validation without running the controller code.

The Form Component

The Form component now has direct support for Precognition and provides useful methods such as valid() and invalid():

<template>
 <Form action="/users" method="post" #default="{ errors, invalid, validate, validating }">
   <div>
     <input name="name" @change="validate('name')" />
     <p v-if="invalid('name')"> {{ errors.name }} </p>
   </div>
 
   <div>
     <input name="email" @change="validate('email')" />
     <p v-if="invalid('email')"> {{ errors.email }} </p>
   </div>
 
   <p v-if="validating">Validating...</p>
 </Form>
</template>

There are many more options and customizations available with this release. See Pull Request #2700 for implementation details. The documentation will help you get started with Precognition with the <Form/> component.

The useForm() Helper

You can use Precognition with the useForm() helper using the withPrecogition() method like so:

import { useForm } from '@inertiajs/vue3'
 
const form = useForm({
   name: '',
   email: '',
}).withPrecognition('post', '/users')

See Pull Request #2684 for implementation details, and the documentation for using Precognition with useForm().

Release notes

You can see the complete list of new features and updates below and the diff between 2.2.21 and 2.3.0 on GitHub. The following release notes are directly from the changelog:

v2.3.0

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Sponsored

laravelcloud logo
Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Visit Laravel Cloud

The latest

View all →
CPX: The Composer Package Executor for PHP image

CPX: The Composer Package Executor for PHP

Read article
Laravel AI SDK Adds Human-in-the-Loop Tool Approval image

Laravel AI SDK Adds Human-in-the-Loop Tool Approval

Read article
Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals image

Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals

Read article
Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs image

Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs

Read article
Blade Formatting in Laravel Pint image

Blade Formatting in Laravel Pint

Read article
Inertia DevTools Is Now on the Chrome Web Store image

Inertia DevTools Is Now on the Chrome Web Store

Read article