F
Filament17mo ago
notwut

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');
}
}
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])
Jump to solution
3 Replies
Solution
Tin
Tin17mo ago
Can you use $this->form->fill(['date' => $date])
Tin
Tin17mo ago
I think that would work
notwut
notwutOP17mo ago
Thanks, it worked with $this->form->fill(['date' => $date]) after I added ->afterStateHydrated().
Want results from more Discord servers?
Add your server