F
Filament2y 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
I think you need Filament\Forms\Components\Actions\Action for that instead of Filament\Actions\Action
LeandroFerreira
->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
xyOP2y ago
Thanks!
manper555
manper5552y 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
toeknee2y 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
manper5552y 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
toeknee2y ago
Please feel free to do a PR on the docs 🙂
manper555
manper5552y 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:...

Did you find this page helpful?