reuse existing resource in select (createOptionForm)

i want to reuse the same form in resource in select createOptionForm, filament's team did great work in re-using it in relationship managers, anyway to use it in select createOptionForm too ?
3 Replies
Fogzy
Fogzy7mo ago
I stumbled upon this when asking the same thing. Did you find a way to reuse the resource form?
Tieme
Tieme7mo ago
I have made it as followed Primary resource
public static function form(Form $form): Form
{
return $form
->schema(self::FormComponents());
}

public static function FormComponents()
{
return [
Forms\Components\TextInput::make('name')
->label('Some stupid label')
->required()
->columnSpanFull(),
];
}
public static function form(Form $form): Form
{
return $form
->schema(self::FormComponents());
}

public static function FormComponents()
{
return [
Forms\Components\TextInput::make('name')
->label('Some stupid label')
->required()
->columnSpanFull(),
];
}
Other resources or classes
Forms\Components\Select::make('this_is_it')
->label('Something new')
->relationship(name: 'this', titleAttribute: 'name')
->multiple()
->searchable()
->preload()
->createOptionForm(PrimaryResource::FormComponents()),
Forms\Components\Select::make('this_is_it')
->label('Something new')
->relationship(name: 'this', titleAttribute: 'name')
->multiple()
->searchable()
->preload()
->createOptionForm(PrimaryResource::FormComponents()),
Fogzy
Fogzy7mo ago
Yeah I did the same workaround, but anyway, would be nicer to be able to use the method directly. That would mean that the form object has to be visible for the createOptionForm closure… Thanks anyway.
Want results from more Discord servers?
Add your server