ux icon indicating copy to clipboard operation
ux copied to clipboard

[Live] Consider allowing new array keys to be added to model on the frontend

Open weaverryan opened this issue 3 years ago • 5 comments

Suppose this setup:

<input type="checkbox" data-model="users[0]" value="tim">
<input type="checkbox" data-model="users[1]" value="ryan">

And in the component:

#[LiveProp(writable: true)]
public array $users = [];

If you try this, you'll get the JavaScript error:

The model name users.0 was never initialized. Did you forget to add exposed={"0"} to its LiveProp?

This is by design, though the original rationale is related to objects, and not allowing object properties to be modified by the user unless allowed by the user: https://symfony.com/bundles/ux-live-component/current/index.html#modifying-nested-object-properties-with-the-exposed-option

We need to think if this makes sense for arrays... of if there should be a way to "allow any nested keys" in a writable array. Or if an array property is writable, shouldn't that mean that it can be changed in any way (including adding new keys)?

weaverryan avatar Aug 12 '22 00:08 weaverryan

Is this in response to the slack issue by @maartendekeizer?

kbond avatar Aug 12 '22 12:08 kbond

It is, yes :). Relates now to #425

weaverryan avatar Aug 14 '22 11:08 weaverryan

Thank you for this issue. There has not been a lot of activity here for a while. Has this been resolved?

carsonbot avatar Apr 26 '24 12:04 carsonbot

Could I get a reply or should I close this?

carsonbot avatar May 11 '24 07:05 carsonbot

Hey,

I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen!

carsonbot avatar May 25 '24 14:05 carsonbot