laravel/precognition

Cannot use 'data' as a form property

adriaanzon opened this issue · 2 comments

Laravel Precognition Plugin Version

0.5.3

Laravel Version

10.40.0

Plugin

Vue

Description

Because the properties of the form are merged together with form functions here, it's not possible to have a property on the form that has the same name as any of the functions.

Steps To Reproduce

Example setup function of a Vue component, using a 'data' property:

const form = useForm('post', '/api/my-endpoint', {
    'data': {
        'foo': 1,
        'bar': 2,
    },
    'some_other_property': 1,
});

return { form };

When trying to submit the form using form.submit(), you'll get the following error because the 'data' property conflicts with the data function:

TypeError: form.data is not a function. (In 'form.data()', 'form.data' is an instance of ProxyObject)

This is indeed unfortunately a reserved keyword.

This is a pattern we borrowed from Inertia to ensure that integration with Inertia forms was seamless.

There are a few functions on the forms class that are "reserved" words. Sorry you had troubles here.