"anonymous" actions to a form but only on edit?

I have a form for creating/editing articles. I want to add a "preview" button that just loads the url..
Action::make('preview')
->icon('heroicon-o-arrow-top-right-on-square')
->color('gray')
->url(fn (Set $set, $state): string => $state['slug'] ? route('article.details', ['slug' => $state['slug']]) : '')
Action::make('preview')
->icon('heroicon-o-arrow-top-right-on-square')
->color('gray')
->url(fn (Set $set, $state): string => $state['slug'] ? route('article.details', ['slug' => $state['slug']]) : '')
Is it possible to tell the action to not display if it's on the create page? Or when $state['slug'] is empty?
2 Replies
awcodes
awcodes11mo ago
Simple solution, only add the action to the EditArticle class. Otherwise ‘->hidden(fn($context) => $context === ‘create’)` I think actions support context.
ericlbarnes
ericlbarnes11mo ago
->hidden did the trick. Thanks