What is the best way to re-use schemas when just using tables/forms packages?
I am just starting to build an app that will just use the tables/forms package. I've started with a simple model and a "create model" component. It's a bit complex, so it's still a work in progress.
In any case, I'm far enough along where I can see that I will have to basically recreate the same form definition for an "edit model" component.
I'm wondering what the best/recommended way might be to keep the definition in one place...?
When using the admin package, the schema is defined once and you can show/hide/whatever based on whether you're creating/editing. I can't seem to find how one might be able to do this when just using tables/forms.
I hope this makes sense. Thx in advance for any help. 🤓
9 Replies
question makes sense
but i think you're overcomplicating
its just PHP
you can return a form schema or table columns array from anywhere
Invokable class, any method, static method
and just pass it in
OK. That makes sense, of course, but that suggests that there's nothing "built-in"....like we have in the admin package, right...?
i dont see the need for anything to be built in?
So...just have the schema any ol' place and (re)use for both create/edit....sounds simple enough.
Thx.
define a
getFormSchema()
static method on your model and return from there
or on a wrapper around your modelWell, in the admin package, there is the WidgetResource, which has the form/table definitions...and the form definitions are used for the CreateWidget and EditWidget classes. That's what I was talking about. 🤓
a resource is just a model wrapper so you can write your own
any old PHP class will work
you could even put getFormSchema() in a trait and reuse it between components
that would also work
Well you can have App\Resources if that makes you feel more like home 😂
@Dan Harrin Thx...! 👍