Maxxx22
Maxxx22
FFilament
Created by Maxxx22 on 10/27/2023 in #❓┊help
Repeater: show delete button on each line conditionally
I am trying to let the user only delete repeater records with certain data conditions. Currently I only managed to stop the delete action but I think there must be a way where I can even conditionally show/hide the delete button based on the data within the record.
Repeater::make('Links')
->relationship('weblinks')
->schema([
TextInput::make('url')
->url()
->disabled(fn (Get $get) => !Weblink::typeEditable($get('type'))) //readonly on some types
->dehydrated(),
Select::make('type')
->options(Weblink::getSelectWeblinkType())
->disabled(fn (Get $get) => !Weblink::typeEditable($get('type')))
->dehydrated()
])
->addActionLabel('New Link')
->defaultItems(0)
->deleteAction(function (Action $action) {
return $action->before(function ($state, $arguments, $action) {
if (isset($state[$arguments["item"]])) {
$item_id = Arr::get($arguments, "item");
$item = Arr::get($state, $item_id);
$type = Arr::get($item, "type");
if (Weblink::typeEditable($type)) {
return $action->hidden(false);
} else {
Notification::make()
->title('Error')
->body("Type not allowed")
->status('danger')
->send();
return $action->cancel();
}
}
});
})
Repeater::make('Links')
->relationship('weblinks')
->schema([
TextInput::make('url')
->url()
->disabled(fn (Get $get) => !Weblink::typeEditable($get('type'))) //readonly on some types
->dehydrated(),
Select::make('type')
->options(Weblink::getSelectWeblinkType())
->disabled(fn (Get $get) => !Weblink::typeEditable($get('type')))
->dehydrated()
])
->addActionLabel('New Link')
->defaultItems(0)
->deleteAction(function (Action $action) {
return $action->before(function ($state, $arguments, $action) {
if (isset($state[$arguments["item"]])) {
$item_id = Arr::get($arguments, "item");
$item = Arr::get($state, $item_id);
$type = Arr::get($item, "type");
if (Weblink::typeEditable($type)) {
return $action->hidden(false);
} else {
Notification::make()
->title('Error')
->body("Type not allowed")
->status('danger')
->send();
return $action->cancel();
}
}
});
})
I tried to make a similar condition in function Repeater->deleteable(function (...)) but here I don't have access to the $arguments, so I cant say which element of the state I am currently processing. Still the current solution I showed above is working for me but it feels wrong. I think there is a much easier way, I am just not seeing it yet probably.
3 replies
FFilament
Created by Maxxx22 on 4/12/2023 in #❓┊help
Customize table default search debounce behavior
I am currently using a filament table search at one of the main pages of the website. If the users enters a letter, the search will be triggered immediately which creates some db load. How could I customize the default search to require a minimum of letters to be entered, search only when leaving the field or on enter, debounce timing and so on. I was able to do this with a custom form in a TextInput on getTableFilters with min() and lazy() but not with the default search field. Any recommendations how to do this?
protected function getTableColumns(): array
{
return [
Tables\Columns\TextColumn::make('name')
->limit(40)
->searchable(query: function (Builder $query, string $search): Builder {
return $query
->where('name', 'like', "%{$search}%")
->orwhereRelation('names', 'name', 'like', "%{$search}%");
}),
];
}
protected function getTableColumns(): array
{
return [
Tables\Columns\TextColumn::make('name')
->limit(40)
->searchable(query: function (Builder $query, string $search): Builder {
return $query
->where('name', 'like', "%{$search}%")
->orwhereRelation('names', 'name', 'like', "%{$search}%");
}),
];
}
6 replies
FFilament
Created by Maxxx22 on 4/12/2023 in #❓┊help
Reactive table filters without Livewire request
I try to customize a table filter to have a simple filter for all the basic fields and a advanced filter for basics and special cases. So far it is working, but every time I toggle between basic and advanced a request is triggered. What would be the approach to do this in the frontend only without the request?
protected function getTableFilters(): array
{
return [
Filter::make('my_filtere')
->form([
Forms\Components\Toggle::make('advanced_filter')
->default(false)
->dehydrated(false),
Forms\Components\Select::make('country_id')
->label('Land')
->options(Country::all()->pluck('full_name', 'id')->toArray()),
Forms\Components\Select::make('region_id')
->label('Region')
->options(Region::all()->pluck('full_name', 'id')->toArray()),
Forms\Components\Select::make('subregion_id')
->hidden(fn (Closure $get) => $get('advanced_filter') == false) //has to be in the same form !!!
->label('Subregion')
->options(Subregion::all()->pluck('full_name', 'id')->toArray()),
])
];
}
protected function getTableFilters(): array
{
return [
Filter::make('my_filtere')
->form([
Forms\Components\Toggle::make('advanced_filter')
->default(false)
->dehydrated(false),
Forms\Components\Select::make('country_id')
->label('Land')
->options(Country::all()->pluck('full_name', 'id')->toArray()),
Forms\Components\Select::make('region_id')
->label('Region')
->options(Region::all()->pluck('full_name', 'id')->toArray()),
Forms\Components\Select::make('subregion_id')
->hidden(fn (Closure $get) => $get('advanced_filter') == false) //has to be in the same form !!!
->label('Subregion')
->options(Subregion::all()->pluck('full_name', 'id')->toArray()),
])
];
}
4 replies
FFilament
Created by Maxxx22 on 3/3/2023 in #❓┊help
How do I refresh select options when I generate new options within the same wizard
Hello, I love using filament so far, everything was kind of well documented to me, but currently I am stuck on the following topic .... - I use a wizard to generate new data based on the data entered in the step before - In a select box I want to display the generated data but the options data is not refreshed, so the users is confused I created some dummy repo as a test case, see here https://github.com/canyoningdb/filament-question1. The major logic is in this file https://github.com/canyoningdb/filament-question1/blob/main/app/Filament/Resources/CanyonResource/Pages/CreateCanyon.php Big thanks for hints and help, Max
7 replies