F
Filament13mo ago
Wim

Different sections on Create and Edit form

I have a form with a grid and 4 sections as follows:
public static function form(Form $form): Form {
return $form
->schema([
Grid::make(4)
->schema([
Section::make(__('products.general_info'))
Section::make(__('products.publish_info'))
Section::make(__('products.medical_social_info'))
Section::make(__('products.media'))
]);
}
public static function form(Form $form): Form {
return $form
->schema([
Grid::make(4)
->schema([
Section::make(__('products.general_info'))
Section::make(__('products.publish_info'))
Section::make(__('products.medical_social_info'))
Section::make(__('products.media'))
]);
}
As it is now all 4 sections are displayed on the create and the edit page. I would want to change it so that section publish_info is only shown on the edit page.
2 Replies
Tieme
Tieme13mo ago
think this will work
Grid::make(4)
->schema([
Section::make(__('products.general_info'))
Section::make(__('products.publish_info'))
Section::make(__('products.medical_social_info'))
Section::make(__('products.media'))
])
->visible(fn ($context): int => $context === 'edit');
Grid::make(4)
->schema([
Section::make(__('products.general_info'))
Section::make(__('products.publish_info'))
Section::make(__('products.medical_social_info'))
Section::make(__('products.media'))
])
->visible(fn ($context): int => $context === 'edit');
Wim
WimOP13mo ago
Thanks for your suggestion. The below works:
Grid::make(4)
->schema([
Section::make(__('products.general_info'))
Section::make(__('products.publish_info'))->visible(fn ($context): int => $context === 'edit')
Section::make(__('products.medical_social_info'))
Section::make(__('products.media'))
])
Grid::make(4)
->schema([
Section::make(__('products.general_info'))
Section::make(__('products.publish_info'))->visible(fn ($context): int => $context === 'edit')
Section::make(__('products.medical_social_info'))
Section::make(__('products.media'))
])
Follow up question though: would there be a way that the content of the publish info is different whether displayed on the create page compared to being displayed on the edit page?

Did you find this page helpful?