F
Filamentβ€’2y ago
Matthew

Assuming im on a Page, and I have a getTableHeading and a form with a Select.

If I click on a Select option, then I want the Heading to get the name of the option that I clicked. Is that even an option?
4 Replies
Patrick Boivin
Patrick Boivinβ€’2y ago
Is this a custom page? Can you share a screenshot?
Matthew
MatthewOPβ€’2y ago
Yes its a custom page
protected function getTableHeading(): string|Htmlable|Closure|null
{
return "custom vehicle title";
}



// Specify filters for tables
protected function getTableFilters(): array
{

return [
Filter::make('complex_filters')->columnSpan(4)
->form([


Card::make([
Select::make('vehicle_id')
->required()
->options(Vehicle::all()->sortBy('name')->pluck('name', 'id'))->preload()
->searchable(),
]),

])
];
}
protected function getTableHeading(): string|Htmlable|Closure|null
{
return "custom vehicle title";
}



// Specify filters for tables
protected function getTableFilters(): array
{

return [
Filter::make('complex_filters')->columnSpan(4)
->form([


Card::make([
Select::make('vehicle_id')
->required()
->options(Vehicle::all()->sortBy('name')->pluck('name', 'id'))->preload()
->searchable(),
]),

])
];
}
Patrick Boivin
Patrick Boivinβ€’2y ago
Never really done it but I'm thinking this could be a simple solution: Add a property on your page class:
public string $customHeading = 'Initial Heading';

protected function getTableHeading()
{
return $this->customHeading;
}
public string $customHeading = 'Initial Heading';

protected function getTableHeading()
{
return $this->customHeading;
}
Then add on your Select field:
->afterStateUpdated(function ($livewire, $state) {
$livewire->customHeading = $state;
})
->afterStateUpdated(function ($livewire, $state) {
$livewire->customHeading = $state;
})
The $state here will be the vehicle ID... but you get the idea πŸ˜„
Matthew
MatthewOPβ€’2y ago
Thank you! As you said this was very close but I managed to do the rest. This gives the id only, so if you want the name of it, you have to do it this way:
$livewire->customHeading = Vehicle::find($state)->first()->name;
$livewire->customHeading = Vehicle::find($state)->first()->name;
Want results from more Discord servers?
Add your server