Event Not Dispatching to other 'TaskUpdateModal' Component

I’m having trouble dispatching an event to another Livewire component (TaskUpdateModal) in my Laravel project using Livewire 3. The event dispatch seems correct, but the listener in the TaskUpdateModal component is not triggered, and I can’t figure out why. 1.In the TaskTable component, I’m dispatching the event like this:
->actions([
Action::make('in_progress')
->action(function (Task $task) {
$this->updateStatus($task, 'in_progress'); // Call updateStatus
$this->dispatch('TaskUpdateModal', taskId: $task->id, status: 'in_progress'); // Dispatch to TaskUpdateModal
})
->label('In Progress')->color('warning')->icon('heroicon-o-forward')
->disabled(fn(Task $task) => $task->status === 'in_progress' || $task->status === 'completed')
->tooltip(fn(Task $task) => $task->status === 'in_progress' ? 'Task is already in progress' : ($task->status === 'completed' ? 'Task is completed, cannot mark in progress' : '')),
])
->actions([
Action::make('in_progress')
->action(function (Task $task) {
$this->updateStatus($task, 'in_progress'); // Call updateStatus
$this->dispatch('TaskUpdateModal', taskId: $task->id, status: 'in_progress'); // Dispatch to TaskUpdateModal
})
->label('In Progress')->color('warning')->icon('heroicon-o-forward')
->disabled(fn(Task $task) => $task->status === 'in_progress' || $task->status === 'completed')
->tooltip(fn(Task $task) => $task->status === 'in_progress' ? 'Task is already in progress' : ($task->status === 'completed' ? 'Task is completed, cannot mark in progress' : '')),
])
2.In the TaskUpdateModal component, I have the listener set up like this:
class TaskUpdateModal extends Component
{
public $taskId;
public $status;

protected $listeners = ['TaskUpdateModal'];

public function TaskUpdateModal($taskId, $status)
{
$this->taskId = $taskId;
$this->status = $status;

// Additional logic
}
}
class TaskUpdateModal extends Component
{
public $taskId;
public $status;

protected $listeners = ['TaskUpdateModal'];

public function TaskUpdateModal($taskId, $status)
{
$this->taskId = $taskId;
$this->status = $status;

// Additional logic
}
}
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server