F
Filament12mo ago
Watoka

tag

Refresh resource form data form action I have a form in a resource where I am populating a relationship repeater from a section header action. After the relationship is populated, I need to refresh the repeater to show the newly populated data, but I cannot use the $this->refreshFormData() method because I am in a static class. Probably there is a workaround for this. My simplified code:
Forms\Components\Section::make('Client Rates')
->live()
->headerActions([
Action::make('add_group_preset')
->label('Add Group Preset')
->requiresConfirmation()
->form([
Forms\Components\Select::make('group_id')
->label('Author')
->options(ServiceGroup::query()->isActive()->pluck('name', 'id'))
->required(),
])
->action(function (array $data, $record, $livewire) {

// Add service items
//...
// refresh service items after adding a group preset
$this->refreshFormData(['serviceItems']);
}),
])
->schema([
TableRepeater::make('serviceItems')
//->headers(['Service Items', 'Default Rate'])
->relationship()
->live()
//...
->schema([
Forms\Components\Select::make('service_item_id')
->label('Service Item')
->relationship('serviceItem', 'name',
fn(Builder $query) =>
$query->where('active', 1)
->where('category', 'visit'))
->preload()
->distinct()
->live(),
Forms\Components\TextInput::make('default_rate')
->label('Default Rate'),

])
]),
Forms\Components\Section::make('Client Rates')
->live()
->headerActions([
Action::make('add_group_preset')
->label('Add Group Preset')
->requiresConfirmation()
->form([
Forms\Components\Select::make('group_id')
->label('Author')
->options(ServiceGroup::query()->isActive()->pluck('name', 'id'))
->required(),
])
->action(function (array $data, $record, $livewire) {

// Add service items
//...
// refresh service items after adding a group preset
$this->refreshFormData(['serviceItems']);
}),
])
->schema([
TableRepeater::make('serviceItems')
//->headers(['Service Items', 'Default Rate'])
->relationship()
->live()
//...
->schema([
Forms\Components\Select::make('service_item_id')
->label('Service Item')
->relationship('serviceItem', 'name',
fn(Builder $query) =>
$query->where('active', 1)
->where('category', 'visit'))
->preload()
->distinct()
->live(),
Forms\Components\TextInput::make('default_rate')
->label('Default Rate'),

])
]),
1 Reply
Watoka
WatokaOP12mo ago
Sorry, I think i messed up something while creating this post
Want results from more Discord servers?
Add your server