insert default value into form with custom action in create

Hi how do i set a default value with an action button into the form in the resource file, instead of creating a new form
class CreateStatisticReport extends CreateRecord
{
protected static string $resource = StatisticReportResource::class;

protected function getActions(): array
{
return [
// ->action('impersonate'),
Actions\Action::make('set')
->action('setDefault'),

];
}
}
class CreateStatisticReport extends CreateRecord
{
protected static string $resource = StatisticReportResource::class;

protected function getActions(): array
{
return [
// ->action('impersonate'),
Actions\Action::make('set')
->action('setDefault'),

];
}
}
8 Replies
RickDB
RickDB2y ago
Do you want to fill in an input when user clicks action?
BATMAN
BATMANOP2y ago
yes
RickDB
RickDB2y ago
Use a closure and use $set, that should work
BATMAN
BATMANOP2y ago
but it says Target [Closure] is not instantiable. this code is in the 'CreateStatisticReportResource' not in the 'StatisticReportResource'
public static function form(Form $form): Form
{
return $form
->schema([
Card::make()
->schema([
Select::make('nomination_ids')
->label('Nominations')
->options(Nomination::pluck('name','id'))
->multiple()
->required(),

Select::make('nomination_stages')
->label('Nomination Stages')
->options(Application::STATUS)->multiple()
->required(),
])

//
]);
}
public static function form(Form $form): Form
{
return $form
->schema([
Card::make()
->schema([
Select::make('nomination_ids')
->label('Nominations')
->options(Nomination::pluck('name','id'))
->multiple()
->required(),

Select::make('nomination_stages')
->label('Nomination Stages')
->options(Application::STATUS)->multiple()
->required(),
])

//
]);
}
this form is in the StatisticReportResource
LeandroFerreira
Actions\Action::make('set')
->action(function () {
$this->data['field'] = 'new value';
}),
Actions\Action::make('set')
->action(function () {
$this->data['field'] = 'new value';
}),
?
BATMAN
BATMANOP2y ago
lol didnt know it was that simple thx alot
LeandroFerreira
I'm thrilled to see that Batman is using Filament! It's great to see superheroes embracing new technology. LOL
toeknee
toeknee2y ago
Couldn't agree more! To the bat cave

Did you find this page helpful?