Open modal when user clicks button, show details of item clicked.

I have a livewire component (modal) that receives an ID on mount and doesn't have data until the user clicks a button. The form isn't getting a default value, presumably because it's getting initialized when the page loads (no data yet), and then nothing happens when a user clicks the button. I could be wrong about this, but if I'm right, how can I defer loading the form until the data is there to populate it.

class EditMonthEndTask extends Component implements HasForms, HasInfolists
{
    use InteractsWithInfolists, InteractsWithForms;

    public array $task = [];
    public $taskId;
    protected Team $team;

    protected $listeners = ['editTask'];

    public function mount(int $taskId = null): void
    {
        $this->taskId = $taskId;
        $this->task = (!empty($taskId)) ? MonthEndTask::find($taskId)->toArray() : [];
        $this->team = SelectedLocation::get()->team ?? new Team();
        $this->form->fill();
    }

    public function render()
    {
        return view('livewire.components.month-end.edit-month-end-task', ['task' => $this->task]);
    }

    public function form(Form $form): Form
    {
        return $form->schema([
            TextInput::make('title')->required()->default($this->task['title'] ?? ''),
        ])->statePath('task');
    }
}
Was this page helpful?