Get Schema from Form for createOptionForm()I
Is it possible to get the schema from an exsiting Resource to pass it to createOptionForm() of another resource without reapting yourself or without chaging anything in the origin resoruce?
In Filament 2.0 I think there was getSchema() on Form class. Now it's gone.
Is there another option?
10 Replies
You can use this:
https://filamentphp.com/docs/3.x/panels/resources/relation-managers#sharing-a-resources-form-and-table-with-a-relation-manager
DOn't mind being in the relation-manager section.
Just call the static function form from the resource you want and pass it the $form param
That's what I am doing for relation managers but for createOptionForm it doesn't work for me:
Filament\Forms\Components\Select::createOptionForm(): Argument #1 ($schema) must be of type Closure|array|null, Filament\Forms\Form given

->createOptionForm([ClusterResource::form($form)]) maybe it works :/
What I tend to do is put a static function on the resource called ‘formSchema’ which returns an array and just re-use it where I need too.
@toeknee Yes, that would be a wordaround, but would always need to manipulate the origin resource.
Unfortunately no.. The error comes a bit later. I can now see and click the plus, but immediately get this one now..
Filament\Forms\ComponentContainer::Filament\Forms\Concerns\{closure}(): Argument #1 ($component) must be of type Filament\Forms\Components\Component, Filament\Forms\Form given
the InteractWithForms trait has this function getFormSchema() that returns an array.
maybe you can play with
If that doesnt work, you can go with the function like toeknee said or manually put the form inputs :/
I was running into this earlier today this should work
Well it’s not always? You just need to add a single function to the origin resource? You can’t have that many resources that a simple function is an issue?
Of course I can adjust all the resources I have but doesn't feel as a great approach. It's more a workaround.
Sounds good. Will try this later this day.