How can I add Actions to the body of Sections?

Its all in the title:)
10 Replies
DarkKnight
DarkKnight6mo ago
Maybe the best way is to create a view field (custom field) that looks like an action. Right?
awcodes
awcodes6mo ago
Look up anonymous actions in the docs.
DarkKnight
DarkKnight6mo 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
awcodes6mo ago
you don't need a view field
DarkKnight
DarkKnight6mo ago
OH I see now
awcodes
awcodes6mo 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
DarkKnight6mo ago
wow yeah, my bad I misunderstood this. Thank you Is it also possible to have widgets/charts inside of Section?
awcodes
awcodes6mo ago
for that you would need a custom component.
awcodes
awcodes6mo ago
Yes.