FilamentF
Filament15mo ago
Sandeep

Issue: Disappearing Button on Dashboard Stat Widget

I'm trying to add a button labeled "Fix Errors" to a Stat widget on the dashboard. The goal is to have this button trigger a public function when clicked, which then executes a command to fix the errors. However, I'm encountering an issue where the button disappears after it is clicked, even though the function is called correctly.

Can someone help me figure out why the button is disappearing and how to prevent it? Below is the code, I'm using and I've also attached the code php file and a screenshot for reference.

protected function getStats(): array
    {

        $errorCount = Product::where('is_error', true)->count();

        return [
            Stat::make('Product Sync Errors', $errorCount)
                ->description('Number of products with sync errors')
                ->color('danger')
                ->extraAttributes([
                    'class' => 'relative cursor-pointer',
                    'x-data' => '{}',
                    'role' => 'button',
                    'tabindex' => '0',
                    'aria-label' => 'Filter Product Sync Errors',
                    'x-init' => "
            let button = document.createElement('button');
            button.className = 'absolute top-0 right-0 mt-2 mr-2 px-2 py-1 text-sm text-white bg-blue-500 rounded hover:bg-blue-600';
            button.setAttribute('aria-label', 'Fix Errors');
            button.innerText = 'Fix Errors';
            button.setAttribute('wire:click', `\$dispatch('setStatusFilter',{ filter: ['processed', {$errorCount}]})`);
            \$el.appendChild(button);
        ",
                ]),


                ];
    }
Was this page helpful?