cj
cj
FFilament
Created by cj on 3/15/2024 in #❓┊help
Is it possible to add an ImportAction to a form tab?
I would like to add a button for an ImportAction to a tab on a resource's form.
I understand that ImportAction isn't an acceptable type for this use, but I'm also struggling to find a workaround. Any ideas?
Filament\Forms\Components\Actions::Filament\Forms\Components\{closure}(): Argument #1 ($action) must be of type Filament\Forms\Components\Actions\Action, Filament\Actions\ImportAction given
Filament\Forms\Components\Actions::Filament\Forms\Components\{closure}(): Argument #1 ($action) must be of type Filament\Forms\Components\Actions\Action, Filament\Actions\ImportAction given
Tabs\Tab::make('Tab 1')
Actions::make([
// This action works fine
Actions\Action::make('View Some Stuff')
->url(function ($record): string {
return 'https://yahoo.com';
})
->openUrlInNewTab(),

// This throws an exception because ImportAction isn't an acceptable type
ImportAction::make('importStuff')
->label('Import Stuff')
->importer(StuffImporter::class)
->options(['thing_id' => 1]),
Tabs\Tab::make('Tab 1')
Actions::make([
// This action works fine
Actions\Action::make('View Some Stuff')
->url(function ($record): string {
return 'https://yahoo.com';
})
->openUrlInNewTab(),

// This throws an exception because ImportAction isn't an acceptable type
ImportAction::make('importStuff')
->label('Import Stuff')
->importer(StuffImporter::class)
->options(['thing_id' => 1]),
4 replies
FFilament
Created by cj on 3/14/2024 in #❓┊help
Passing values to CreateAction for form population
I have a relationmanager with the CreateAction in the header. I would like to populate the resulting form with data from the parent class, but I can't seem to figure out the process. I've tried setting the form data in a variety of ways, but nothing seems to pass on to the resulting form. In the code below, I'm trying to populate the TextInput for the 'name' field. Can someone point me in the right direction?
public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('name'),
]);
}

public function table(Table $table): Table
{
$table = MyResource::table($table);

return $table
->filters([])
->headerActions(actions: [
Tables\Actions\CreateAction::make()
->formData([
'name' => 'hoo', // nope, doesn't work
])
->mutateFormDataUsing(function (array $data): array {
\Log::info('mutateFormDataUsing: never gets called');
$data['name'] = 'goo';

return $data;
})
->beforeFormFilled(function () {
\Log::info('beforeFormFilled: called, but doesn\'t seem to do anything');
$data['name'] = 'foo';

return $data;
})
->modalWidth('7xl')
->createAnother(false),
]);
public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('name'),
]);
}

public function table(Table $table): Table
{
$table = MyResource::table($table);

return $table
->filters([])
->headerActions(actions: [
Tables\Actions\CreateAction::make()
->formData([
'name' => 'hoo', // nope, doesn't work
])
->mutateFormDataUsing(function (array $data): array {
\Log::info('mutateFormDataUsing: never gets called');
$data['name'] = 'goo';

return $data;
})
->beforeFormFilled(function () {
\Log::info('beforeFormFilled: called, but doesn\'t seem to do anything');
$data['name'] = 'foo';

return $data;
})
->modalWidth('7xl')
->createAnother(false),
]);
3 replies
FFilament
Created by cj on 3/7/2024 in #❓┊help
Default Redirect Url
I see that it is possible to change the default redirect url for edit/create for a given resource by creating the function on each resources edit/create file...
protected function getRedirectUrl(): string
{
return $this->getResource()::getUrl('index');
}
protected function getRedirectUrl(): string
{
return $this->getResource()::getUrl('index');
}
but is there a way to set a system default? Instead of the filament default of 'saving the form will not redirect the user to another page', I'd like to set it to return to the list view of a given resource. Do I have to change that on each resources corresponding Edit{Resource} file or is there a simpler way? https://filamentphp.com/docs/3.x/panels/resources/editing-records#customizing-redirects
2 replies
FFilament
Created by cj on 3/2/2024 in #❓┊help
How do I retrieve data from livewire component used in a resource form?
I'm using a custom livewire component as a form field, and that works as expected. However, I can't figure out how to get the data generated in that livewire component back out to the form to save in the resource. I've scoured the documentation, but no luck. Any advice?
16 replies
FFilament
Created by cj on 2/8/2024 in #❓┊help
Is there a way built in way to perform an AttachAction as a bulk action?
I have a relation manager that I'd like to attach objects to in bulk. There doesn't seem to be a built in way to handle that. Is that the case? Ideally, when a user hits the attach action button, the modal that pops up could display a table with filters that the user could modify before attaching all the filtered objects to the primary model.
2 replies
FFilament
Created by cj on 1/29/2024 in #❓┊help
Update a widget from a resource's create form
I have a create form where I'm showing a table widget. This widget should update with potential "attached" models if the user chooses certain options from a select field. The widget is read only. The data is only there for users to validate their choices as they go through the creation process. Is it possible to pass field data of a create form to a footer widget? Right now, the create page for my resource returns the widget in getFooterWidgets(). I've tried updating the widget by using this on the form field in question
->afterStateUpdated(function ($livewire, Get $get) {
$livewire->dispatch('form-updated', $get('select_field_id'));
}),
->afterStateUpdated(function ($livewire, Get $get) {
$livewire->dispatch('form-updated', $get('select_field_id'));
}),
But I'm not sure how to get that information in to the table. Any advice would be appreciated.
2 replies
FFilament
Created by cj on 12/21/2023 in #❓┊help
Possible to add custom dashboard -> filters form to navbar
I have a custom dashboard with a filters form that consists of a couple of select form items that control the widgets on said dashboard. I'd like to add these form items to the navigation bar (I'm using topNavigation). How would I go about doing that?
1 replies