How can I add Actions to the body of Sections?

Its all in the title:)
10 Replies
DarkKnight
DarkKnightOP13mo ago
Maybe the best way is to create a view field (custom field) that looks like an action. Right?
awcodes
awcodes13mo ago
Look up anonymous actions in the docs.
DarkKnight
DarkKnightOP13mo ago
Yeah, I looked it up, but I still cant get it right
Section::make('Cache')
->schema([
ViewField::make('clear_cache')
->view('forms.components.clear-cache-field')
->registerActions(
[
Actions::make([
Action::make('star')
->icon('heroicon-m-star')
->requiresConfirmation()
->action(function () {

}),
Action::make('resetStars')
->icon('heroicon-m-x-mark')
->color('danger')
->requiresConfirmation()
->action(function () {

}),
]),
]
)
])
Section::make('Cache')
->schema([
ViewField::make('clear_cache')
->view('forms.components.clear-cache-field')
->registerActions(
[
Actions::make([
Action::make('star')
->icon('heroicon-m-star')
->requiresConfirmation()
->action(function () {

}),
Action::make('resetStars')
->icon('heroicon-m-x-mark')
->color('danger')
->requiresConfirmation()
->action(function () {

}),
]),
]
)
])
<x-dynamic-component
:component="$getFieldWrapperView()"
:field="$field"
>
<div x-data="{ state: $wire.$entangle('{{ $getStatePath() }}') }">
<x-filament::button>
Test
</x-filament::button>

<!-- {{ $this->getAction('star') }} -->

</div>
</x-dynamic-component>
<x-dynamic-component
:component="$getFieldWrapperView()"
:field="$field"
>
<div x-data="{ state: $wire.$entangle('{{ $getStatePath() }}') }">
<x-filament::button>
Test
</x-filament::button>

<!-- {{ $this->getAction('star') }} -->

</div>
</x-dynamic-component>
awcodes
awcodes13mo ago
you don't need a view field
DarkKnight
DarkKnightOP13mo ago
OH I see now
awcodes
awcodes13mo ago
Section::make('Cache')
->schema([
Actions::make([
Action::make('star')
->icon('heroicon-m-star')
->requiresConfirmation()
->action(function () {

}),
Action::make('resetStars')
->icon('heroicon-m-x-mark')
->color('danger')
->requiresConfirmation()
->action(function () {

}),
]),
])
Section::make('Cache')
->schema([
Actions::make([
Action::make('star')
->icon('heroicon-m-star')
->requiresConfirmation()
->action(function () {

}),
Action::make('resetStars')
->icon('heroicon-m-x-mark')
->color('danger')
->requiresConfirmation()
->action(function () {

}),
]),
])
DarkKnight
DarkKnightOP13mo ago
wow yeah, my bad I misunderstood this. Thank you Is it also possible to have widgets/charts inside of Section?
awcodes
awcodes13mo ago
for that you would need a custom component.
awcodes
awcodes13mo ago
Yes.

Did you find this page helpful?