F
Filamentβ€’3mo ago
kennyhorna

Problem when saving a record in a form that contains a table (custom filament Livewire component)

Morning πŸ‘‹πŸ½ I have the following case. Case I have the SaleTrackingResource. This resource has a 1-M relationship with SaleDay, that in turn, has a 1-M relationship with SaleDayEntry. - SaleTrackingResource 1-m SaleDay 1-m SaleDayEntry Since I need to display the SaleDayEntry objects in a table in the SaleTrackingResource, I created a custom Livewire component, ListSaleDayEntries. I extended the Livewire\Component class and it implements the HasForms& HasTable interfaces. It looks like this [Image 1]. How it's rendered: In the SaleTrackingResource, I have a section that renders the SaleDays dynamically. Each day will have a tab, and within that tab is that I make a new instance of the custom Livewire component I mentioned earlier, the ListSaleDayEntries. This is the relevant code:
Section::make('saleDays')
->label('Tours')
->visibleOn('edit')
->columns(1)
->collapsible()
->headerActions([
Action::make('create-day')
->label('Agregar DΓ­a')
->url(fn(?SalesTracking $record) => CreateTourSaleDay::getUrl([
'sales_tracking_id' => $record?->id,
]))
])
->schema([
Tabs::make('tourSaleDays')
->hiddenLabel()
->hidden(fn(?SalesTracking $record) => ! $record?->tourSaleDays()->exists())
->schema(
fn(?SalesTracking $record) => $record
?->tourSaleDays
->map(fn(TourSaleDay $day) => Tabs\Tab::make($day->name)
->schema([
Livewire::make('entries')
->id($day->id . '-' . $day->name)
->component('list-tour-sale-day-entries')
->data(['record' => $day]),
]))
->toArray() ?? [],
)
]),
Section::make('saleDays')
->label('Tours')
->visibleOn('edit')
->columns(1)
->collapsible()
->headerActions([
Action::make('create-day')
->label('Agregar DΓ­a')
->url(fn(?SalesTracking $record) => CreateTourSaleDay::getUrl([
'sales_tracking_id' => $record?->id,
]))
])
->schema([
Tabs::make('tourSaleDays')
->hiddenLabel()
->hidden(fn(?SalesTracking $record) => ! $record?->tourSaleDays()->exists())
->schema(
fn(?SalesTracking $record) => $record
?->tourSaleDays
->map(fn(TourSaleDay $day) => Tabs\Tab::make($day->name)
->schema([
Livewire::make('entries')
->id($day->id . '-' . $day->name)
->component('list-tour-sale-day-entries')
->data(['record' => $day]),
]))
->toArray() ?? [],
)
]),
Problem I will put the problem in reply below
Solution:
Ok I fixed the problem like this: - I created a view page for the resource. - The custom filament component (the table view) is only visible in the view page - During edition I have the component hidden -> this makes the form to be stored again....
Jump to solution
3 Replies
kennyhorna
kennyhornaβ€’3mo ago
The problem The problem is when you want to save (after an edit) on the big SaleTrackingResource. It just doesn't work or trigger anything. If I comment out that code, then it works again. I think the problem is that some events are being registered when the custom component is added that makes the main one to be ignored. I inspected it with the browser and it doesn't trigger anything. Have you experience that and know how to solve it? Thanks in advance. Anybody? πŸ‘€
Solution
kennyhorna
kennyhornaβ€’3mo ago
Ok I fixed the problem like this: - I created a view page for the resource. - The custom filament component (the table view) is only visible in the view page - During edition I have the component hidden -> this makes the form to be stored again.
kennyhorna
kennyhornaβ€’3mo ago
Not perfect, but I it works I guess πŸ™‚
Want results from more Discord servers?
Add your server