Set form field value from outside the form

I am dispatching the 'set-date' event from the blade of a Livewire component and want to set the value of the 'date' form field in my updateDateFormField() method. This looks something like this.

class EditModel
{
    #[On('set-date')]
    public function updateDateFormField($date)
    {
        $this->data['date'] = $date;
    }

    public function form(Form $form): Form
    {
        return $form
            ->schema([
                DatePicker::make('date'),
                ...
            ])
            ->statePath('data');
    }
}


If I change the value with $this->data['date'] = $date, the value is changed to the date, but ->afterStateUpdated() is not executed. Is there any way I can set the value and ->afterStateUpdated() of my form field 'date' will be executed?
Solution
Can you use $this->form->fill(['date' => $date])
Was this page helpful?