Custom form component with methods

I want to implement custom form field to render a code example which can be copied or injected directly to page with using 2 buttons. I didn't find builtin solution for this so decided to created my own.


<?php

namespace App\Forms\Components;

use Filament\Forms\Components\Field;

class WebIntegrationCode extends Field
{
    protected string $view = 'forms.components.web-integration-code';

    public function copy()
    {
        // TODO: copy to clipboard.
    }

    public function inject()
    {
        // TODO: document.body.appendChild()
    }
}


view:
<x-dynamic-component
        :component="$getFieldWrapperView()"
        :field="$field"
>

    <textarea wire:model="{{ $getStatePath() }}" readonly></textarea>

    <x-filament::button type="button" wire:click="copy">Copy to clipboard</x-filament::button>
    <x-filament::button type="button" wire:click="inject" tooltip="Inject code to current page">Try now</x-filament::button>
</x-dynamic-component>


and this is just a part of action -> modal -> form
            ->actions([
                Tables\Actions\ViewAction::make()->label('View integration')
                    ->modalHeading('Integration')
                    ->form([
                        WebIntegrationCode::make('code'),


But when a press a button Exceptions appears:
Unable to call component method. Public method [copy] not found on component


What's a problem here?
image.png
Was this page helpful?