Skip to content

Conversation

@pascalbaljet
Copy link
Member

This PR adds a defaults() function to the Core validator so that you can pass a data object as new defaults.

The passed data replaces the underlying initialData and oldData, which are used to determine whether a field should be validated, and when resetting a field.

The react-inertia and vue-inertia packages are updated as well to take advantage of the new validator.defaults() function. It now calls defaults() on both Inertia's useForm() helper, as well as the Precognition validator.

import { useForm } from 'laravel-precognition-vue-inertia'

const form = useForm('post', '/register', {
    name: 'John',
})

form.defaults({ name: 'Jane' })

form.name = 'John'
form.reset()

console.log(form.name) // Outputs: 'Jane'

I've added additional tests for core and vue-inertia. There wasn't a test suite for react-inertia, so I ported the tests from the Vue package.

@taylorotwell taylorotwell merged commit 19b1152 into main Nov 26, 2025
2 checks passed
@taylorotwell taylorotwell deleted the defaults-function branch November 26, 2025 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants