F
Filamentβ€’16mo ago
Matthew

Select->default(1) doesnt work in CalendarWidget

I have this issue where if I set a default value in default() the form doesnt show that default value, whereas if I try this in the Resource page, it works. Am I maybe missing something?
Select::make('relation_id')
->label('Client')
->options(Relation::all()->pluck('name', 'id'))
->default(Auth()->user()->time_registration_last_relation_id)
->searchable()
->reactive()
->required()
->afterStateUpdated(fn(callable $set) => $set('project_id', null)),
Select::make('relation_id')
->label('Client')
->options(Relation::all()->pluck('name', 'id'))
->default(Auth()->user()->time_registration_last_relation_id)
->searchable()
->reactive()
->required()
->afterStateUpdated(fn(callable $set) => $set('project_id', null)),
Solution:
I think I figured it out. Here: ```php protected function getCreateEventForm(): array { return [...
Jump to solution
9 Replies
Patrick Boivin
Patrick Boivinβ€’16mo ago
Are you calling $this->form->fill() in your component? (e.g. mount() method)
LeandroFerreira
LeandroFerreiraβ€’16mo ago
@Matthew πŸ‘†
Matthew
MatthewOPβ€’16mo ago
Hey sorry, for late reaction No I dont. The Widget is on the Dashboard. I assume by component, you mean that
Solution
Matthew
Matthewβ€’16mo ago
I think I figured it out. Here:
protected function getCreateEventForm(): array
{
return [
'createEventForm' => $this->makeForm()
->schema(static::getCreateEventFormSchema())
->statePath('createEventFormState')
->fill(), // <- Added this line
];
}
protected function getCreateEventForm(): array
{
return [
'createEventForm' => $this->makeForm()
->schema(static::getCreateEventFormSchema())
->statePath('createEventFormState')
->fill(), // <- Added this line
];
}
Matthew
MatthewOPβ€’16mo ago
But this form is empty for a second before its filled with default data
Matthew
MatthewOPβ€’16mo ago
So when I click on an event, the form shows and its unfilled for a second, then it gets filled
Matthew
MatthewOPβ€’16mo ago
Is this expected or am I filling the form too late?
Patrick Boivin
Patrick Boivinβ€’16mo ago
If I'm reading this correctly, I think this delay is expected... it could be caused by some javascript (e.g. the calendar plugin) that runs before Livewire handles the wire:model directives on the form elements.
Matthew
MatthewOPβ€’16mo ago
Okk! Thank you
Want results from more Discord servers?
Add your server