Livewire actions on form component layout
Hi, I'm creating a custom filament form component layout. I need to exec a function in the controller of the component but wire:click is not working for that.
I create a public function called addPreset in my controller, and in the element I add a wire:click="addPreset".
When I click it trows an error saying method not found.
Solution:Jump to solution
It's ok if you switch to using Event.
protected function setUp(): void
{
parent::setUp();...
6 Replies
Please, can someone help me?
hi
https://filamentphp.com/docs/3.x/actions/adding-an-action-to-a-livewire-component
I think this might be what you need
Yes, in that case the component is type Livewire\Component but to use it in the filament forms, it must be of type Filament\Forms\Components\Component
i think is that the reason why the wire:click doesn't found the component public methods
Can you share your code?
Controller:
Blade view:
The error that trows when I click de button is that can't found public method addBar.
Solution
It's ok if you switch to using Event.
protected function setUp(): void
{
parent::setUp();
$this->registerListeners([
'ProgressBarSection::addBar' => [
function ($component, $customValue) {
// Your code here
Notification::make()->title("You just called ProgressBarSection::addBar ")->send();
},
],
]);
$this->columnSpan('full');
}
Blade view:
<div>
<button
type="button"
wire:click="dispatchFormEvent('ProgressBarSection::addBar', '{{ $getStatePath() }}', 'extra value')"
>Click test demo Event
</button>
</div>