Skip to content

Validation not triggered when Inertia transform changes keys. #84

Open
@ragulka

Description

@ragulka

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:

return originalInputs.reduce<Partial<Data>>((carry, name) => ({
...carry,
[name]: data[name],
}), {}) as Data

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions