F
Filament13mo ago
jaocero

Change modal submit button color

Is possible to change this color the action button only by not using the ->color() ? If I use that it will also change the color in the table action. I only need to change the color in the submit button
Solution:
Solve by making custom action class: ```php <?php namespace App\Filament\CustomActions;...
Jump to solution
3 Replies
jaocero
jaoceroOP13mo ago
No description
Solution
jaocero
jaocero13mo ago
Solve by making custom action class:
<?php

namespace App\Filament\CustomActions;

use Filament\Actions\StaticAction;
use Filament\Tables\Actions\Action;

class CustomAction extends Action
{
public function getModalSubmitAction(): ?StaticAction
{
$action = static::makeModalAction('submit')
->label($this->getModalSubmitActionLabel())
->submit($this->getLivewireCallMountedActionName())
->color($this->getModalIconColor()); // want it to be the same as icon color

if ($this->modalSubmitAction !== null) {
$action = $this->evaluate($this->modalSubmitAction, ['action' => $action]) ?? $action;
}

if ($action === false) {
return null;
}

return $action;
}
}
<?php

namespace App\Filament\CustomActions;

use Filament\Actions\StaticAction;
use Filament\Tables\Actions\Action;

class CustomAction extends Action
{
public function getModalSubmitAction(): ?StaticAction
{
$action = static::makeModalAction('submit')
->label($this->getModalSubmitActionLabel())
->submit($this->getLivewireCallMountedActionName())
->color($this->getModalIconColor()); // want it to be the same as icon color

if ($this->modalSubmitAction !== null) {
$action = $this->evaluate($this->modalSubmitAction, ['action' => $action]) ?? $action;
}

if ($action === false) {
return null;
}

return $action;
}
}
Ximenes
Ximenes10mo ago
can you show how you used it? i've this piece of code and at this point my button wasn't being displayed so i made a new one, but it's white:
public function deleteAction(): Action
{
return Action::make('delete')
->color('danger')
->link()
->icon('heroicon-s-trash')
->requiresConfirmation()
->modalSubmitAction(false)
->extraModalFooterActions(fn (Action $action): array => [
$action->makeModalSubmitAction('ConfirmDeletion', arguments: ['another' => true]),
])
->action(function (array $arguments) {
$user = new User;
$apiToken = $user->getToken();

$attempt = Http::withToken($apiToken, $type = 'Bearer')->delete("http://localhost:8001/api/v1/customers/{$arguments['customer']}", [])->json();

if($attempt == null){
Notification::make()
->title("Unsuccessful deletion!")
->danger()
->send();
}

Notification::make()
->title("Deleted!")
->danger()
->send();

$this->syncData();
});
}
public function deleteAction(): Action
{
return Action::make('delete')
->color('danger')
->link()
->icon('heroicon-s-trash')
->requiresConfirmation()
->modalSubmitAction(false)
->extraModalFooterActions(fn (Action $action): array => [
$action->makeModalSubmitAction('ConfirmDeletion', arguments: ['another' => true]),
])
->action(function (array $arguments) {
$user = new User;
$apiToken = $user->getToken();

$attempt = Http::withToken($apiToken, $type = 'Bearer')->delete("http://localhost:8001/api/v1/customers/{$arguments['customer']}", [])->json();

if($attempt == null){
Notification::make()
->title("Unsuccessful deletion!")
->danger()
->send();
}

Notification::make()
->title("Deleted!")
->danger()
->send();

$this->syncData();
});
}
Want results from more Discord servers?
Add your server