F
Filament9mo ago
cj

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),
]);
1 Reply
cj
cjOP9mo ago
found my answer. needed to set it through ->default on the form, and not by passing it in through the action...
->default(function ($livewire) {
if ($livewire != null && method_exists($livewire, 'getOwnerRecord')) {
return $livewire?->getOwnerRecord()?->id ?? null;
}

return null;
})
->default(function ($livewire) {
if ($livewire != null && method_exists($livewire, 'getOwnerRecord')) {
return $livewire?->getOwnerRecord()?->id ?? null;
}

return null;
})
Want results from more Discord servers?
Add your server