ux
ux copied to clipboard
[Live] Consider allowing new array keys to be added to model on the frontend
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)?
Is this in response to the slack issue by @maartendekeizer?
It is, yes :). Relates now to #425
Thank you for this issue. There has not been a lot of activity here for a while. Has this been resolved?
Could I get a reply or should I close this?
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!