precognition icon indicating copy to clipboard operation
precognition copied to clipboard

Validation not triggered when Inertia `transform` changes keys.

Open ragulka opened this issue 1 year ago • 3 comments

Laravel Precognition Plugin Version

0.5.6

Laravel Version

10.41.1

Plugin

Vue w/ Inertia

Description

In #72, support for Inertia transform was added. However, it looks like it does not support renaming keys, or changing the data structure. In fact, it looks like it only supports transforming individual form field values.

If keys are renamed, or the data structure changes when transforming, then validation is not triggered.

I would expect that changing the data structure with transform is possible and fully supported.

Steps To Reproduce

Implement a form like this:

const form = useForm('patch', '/update', {
    document: {
        customer: { email: '[email protected]' }
        /** other data here **/
    }
}).transform((data) => { ...data.document })
<input type="text" v-model="form.document.customer.email" @change="form.validate('customer.email')" />

Changing the email value will trigger validation all the way until this line:

https://github.com/laravel/precognition/blob/78d440bfcb0d93ef962c779d0701128c7943b8bf/packages/vue/src/index.ts#L87-L90

It stops here, because the keys in originalInputs are based on the initial data, without applying the transformer on it.

ragulka avatar Jul 29 '24 14:07 ragulka