I have a OrderResource i want to have different forms for each create and edit order page?
how can i have this functionailty in orderResource i have this function like
public static function form(Form $form): Form
{
return $form->schema((new Pages\CreateOrder())->createForm());
}
this is working fine i want to change for edit but it is using this form for both craete and edit pages for edit i want likepublic static function form(Form $form): Form
{
return $form->schema((new Pages\CreateOrder())->createForm());
if(editpage){
return $form->schema((new Pages\EditOrder())->editForm());
}
}
i want like this7 Replies
What is different between your desired Create form vs your Edit form?
You can use
->visibleOn('create')
and hiddenOn('edit')
etc to include/exclude things based on the current operation.@DrByte i have wizards on create form and on edit form i have tabs therefore i want this condition or something like from which i can understand now it is edit module or create ?
You can override the Resource's
form()
method directly within your CreateOrder
and EditOrder
classes:
What I usually do then is convert most of the form's fields to separate static functions that return the field. And then in both of my overridden form()
methods I build a schema from an array of function calls to those static methods. That way the fields and their formatting and validation rules etc are kept consistent everywhere I use them.
(I sometimes put those static functions in the Resource, and sometimes put them into a Trait ... depends on how much I'm going to use them elsewhere later. Don't overengineer. It doesn't have to be complicated!)you can also check the operation on the form and return the form you want
@bakriawad thank you
What naming convention do you use for these static functions?
in Resource:
and in the Trait that's imported into various Resources: