Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Providing empty object to the view #573

Closed
kusiormarcin opened this issue Dec 28, 2023 · 1 comment
Closed

Providing empty object to the view #573

kusiormarcin opened this issue Dec 28, 2023 · 1 comment

Comments

@kusiormarcin
Copy link

Hi

Issue: Can't provide empty object to the view.
It's automatically converted to array.
When I use useForm() and provide a prop (data from PHP) to the function, it creates const for every property.

const form = useForm(props.items);

The issue here is that I have a complicated form with multiple objects inside.

Some objects are empty while creating the resource, this is a normal behavior, because there is no data.
These objects are initialized as arrays, and then they accept properties for whatever reason. But they are presented as an array.

When the form is sent, data is visible as incorrect array and PHP is getting empty array.

JS:

Screenshot 2023-12-28 at 15 59 59

PHP:

Screenshot 2023-12-28 at 16 03 27

The only workaround I found is to provide a PHP array with any named index, example:

$object = ['o' => null];

Then it's correctly recognized as Object instead of array.

Any tricks like this doesn't work:

$object = (object)[];
$object = new \stdClass();

Is there any way to resolve this without workarounds?

@driesvints
Copy link
Collaborator

Hi there,

Thanks for reporting but it looks like this is a question which can be asked on a support channel. Please only use this issue tracker for reporting bugs with the library itself. If you have a question on how to use functionality provided by this repo you can try one of the following channels:

However, this issue will not be locked and everyone is still free to discuss solutions to your problem!

Thanks.

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

No branches or pull requests

2 participants