Using $form->schema with Select field's createOptionForm

Hi all I've got a complex form that I've extracted to a separate class for re-use. I'm returning it in resource pages using return MyForm::build($form) and it works well. I'd like to re-use the form for a related resource's select field's ->createOptionForm. Does anyone know of a way to do that? Thanks!
2 Replies
DrByte
DrByte15mo ago
In my projects I tend to create a trait where I put all the shared form-element definitions as separate methods for each field or sometimes for a Section containing some fields. Then in my resources I declare my forms with just a bunch of calls to those methods from the trait. This allows me to selectively ignore certain fields by skipping calling those methods, or replace them with a different method call in certain forms or under certain conditions. So ... it's more of a "reused elements" strategy than a "re use the exact form" in multiple places kind of approach.
binaryfire
binaryfireOP15mo ago
Cool approach, thanks for sharing. I ended up just returning the schema array instead of the form object from my build method. Splitting things into smaller pieces could definitely be useful though.
Want results from more Discord servers?
Add your server