Live Component Updating a parent model from a collection child

53 Views Asked by At

I'm implementing a LiveComponent that contains a collection of child components. Everything works mostly fine, but I don't see how can I update a parent model if the updated property is an array.

Is it possible to set the dataModel property to a value from the collection? Essentially I'm trying to achieve something that would be achieved by this pseudo-code: (notably the 'workShift.tasks.get({{ task.id }})')

computed.tasks|map((task) => {
  component: component('WorkShift:TaskEntry', {
    key: task.id,
    task,
    shift: this.workShift,
    dataModel: 'workShift.tasks.get({{ task.id }})'
  })
})
1

There are 1 best solutions below

1
On

This can be done via events in the components, see: https://symfony.com/bundles/ux-live-component/current/index.html#communication-between-components-emitting-events

see also https://symfony.com/bundles/ux-live-component/current/index.html#actions-in-a-child-do-not-affect-the-parent

(Yes, this is a link answer only - I can't show any meaningful code because it's too dependent on the code kachnitel has and therefore won't make sense.)