Hi guys! I’m pretty new to Livewire and I need a little help to understand what I’m doing wrong.
I’ve created three components: CarIndex, CarEdit and a generic InputAutocomplete which helps me to populate some field. The CarIndex component show a list of cars and the CarEdit component is used to update the model Car.
<!-- CarIndex -->
<table>
<tr>
<th>Actions</th>
</tr>
<tr>
<td>
<span wire:click="$emit('updatingCar', {{ $car->id }})">Edit</span>
</td>
</tr>
</table>
As you can see, when I click on the Edit action I’m updating the current Car in CarEdit component.
class CarEdit extends Component
{
public Car $car;
protected $listeners = ['updatingCar' => 'setCarModel'];
public function setCarModel(int $id): Car
{
return $this->car = Car::findOrFail($id);
}
}
Now, the InputAutocomplete helps me to populate the car owner field, just like a Multiselect, Typeahead, etc. etc. And it should accept the current car owner as default value.
<!-- CarEdit -->
<section>
...Other inputs
<livewire:input-autocomplete :selected="$car->owner"></livewire:input-autocomplete>
</section>
What I’m trying to achieve is that when I click on the action Edit in CarIndex the :selected="$car->owner" is updated accordingly in InputAutocomplete. I know that docs state that “Nested components CAN accept data parameters from their parents, HOWEVER they are not reactive like props from a Vue component”, but I’m wondering if there’s a workaround. I guess an $emitDown event - in order to target only the child component - would solve this case.
Let me know, and thanks!
Matteo.