Prefilling a Field in "Create New Option" Modal of a Select Component in FilamentPHP**

I want to prefill a field in the "create new option" modal, Here's the code I've tried, but it doesn't seem to be effective:
<?php

use App\Filament\Actions\CreateProductInPaddle;
use App\Filament\Resources\ProductResource;
use Filament\Forms\Components\Select;
use Filament\Forms\Form;

Select::make('product_id')
->relationship('product', 'title')
->placeholder('No products available')
->searchable()
->createOptionForm(function (Form $form) {
$form->fill(["title" => "prefilled"]);
return ProductResource::form($form);
})
->createOptionUsing(fn($data, CreateProductInPaddle $action) => $action($data))
->allowHtml()
->required(),
<?php

use App\Filament\Actions\CreateProductInPaddle;
use App\Filament\Resources\ProductResource;
use Filament\Forms\Components\Select;
use Filament\Forms\Form;

Select::make('product_id')
->relationship('product', 'title')
->placeholder('No products available')
->searchable()
->createOptionForm(function (Form $form) {
$form->fill(["title" => "prefilled"]);
return ProductResource::form($form);
})
->createOptionUsing(fn($data, CreateProductInPaddle $action) => $action($data))
->allowHtml()
->required(),
Is there a proper way to prefill data in this scenario with Filament, or is this not supported yet? Any suggestions or code examples would be greatly appreciated.
2 Replies
Helge Sverre
Helge Sverre6mo ago
Alternatively, is there a way to use a function that will eb executed after the form in the modal has been hydrated, in which case, i can jerry-rig it using Get/Set
Mark Chaney
Mark Chaney4mo ago
@Helge Sverre did you ever figure this out. Trying to do this myself as well ok, so the answer is that you can set $action->fillForm([.....]) within the createOptionAction()