F
Filamentβ€’17mo ago
xy

Add action button to form

I'd like to add an action button in the form of a resource. The idea is to use that action method to import details from a model upon clicking it.
public static function form(Form $form): Form
{
return $form
->schema([

// Add action here
]);
}
public static function form(Form $form): Form
{
return $form
->schema([

// Add action here
]);
}
I've tried
Action::make('edit')->button()
Action::make('edit')->button()
in a Section component which results in the following error:
Filament\Forms\ComponentContainer::Filament\Forms\Concerns\{closure}(): Argument #1 ($component) must be of type Filament\Forms\Components\Component, Filament\Actions\Action given
Filament\Forms\ComponentContainer::Filament\Forms\Concerns\{closure}(): Argument #1 ($component) must be of type Filament\Forms\Components\Component, Filament\Actions\Action given
9 Replies
Patrick Boivin
Patrick Boivinβ€’17mo ago
I think you need Filament\Forms\Components\Actions\Action for that instead of Filament\Actions\Action
LeandroFerreira
LeandroFerreiraβ€’17mo ago
->schema([
\Filament\Forms\Components\Actions::make([
\Filament\Forms\Components\Actions\Action::make('myAction')
->action(function () {
//
})
])
...
->schema([
\Filament\Forms\Components\Actions::make([
\Filament\Forms\Components\Actions\Action::make('myAction')
->action(function () {
//
})
])
...
xy
xyOPβ€’17mo ago
Thanks!
manper555
manper555β€’17mo ago
That was very helpful for me. Thanks! More and more how I must pass the record data to the called function to be used in any of my services/classes?
toeknee
toekneeβ€’17mo ago
with $record
->schema([
\Filament\Forms\Components\Actions::make([
\Filament\Forms\Components\Actions\Action::make('myAction')
->action(function ($data, $record) {
// $data will return the submitted form data
// $record will return the model if you are editing
})
])
->schema([
\Filament\Forms\Components\Actions::make([
\Filament\Forms\Components\Actions\Action::make('myAction')
->action(function ($data, $record) {
// $data will return the submitted form data
// $record will return the model if you are editing
})
])
manper555
manper555β€’17mo ago
This is what I needed. Thanks. A very humble suggestion: if a likely example (with component paths) were added to docs it'll save much time to the very noobs as I'm. This product is awesome!
toeknee
toekneeβ€’17mo ago
Please feel free to do a PR on the docs πŸ™‚
manper555
manper555β€’17mo ago
GitHub
Forms Docs - Independent Action button usage (improvement) Β· filame...
IMHO for absolutely noobs as I'm will be very time saving if this example were added to docs: ->schema([ \Filament\Forms\Components\Actions::make([ \Filament\Forms\Components\Actions\Action:...
Want results from more Discord servers?
Add your server