© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
1 reply
jilexandr

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()
    }
}
<?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>
<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
action -> modal -> form

            ->actions([
                Tables\Actions\ViewAction::make()->label('View integration')
                    ->modalHeading('Integration')
                    ->form([
                        WebIntegrationCode::make('code'),
            ->actions([
                Tables\Actions\ViewAction::make()->label('View integration')
                    ->modalHeading('Integration')
                    ->form([
                        WebIntegrationCode::make('code'),


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


What's a problem here?
image.png
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Custom form component
FilamentFFilament / ❓┊help
16mo ago
Initialize custom form component
FilamentFFilament / ❓┊help
3y ago
Custom component load form with dark theme
FilamentFFilament / ❓┊help
2y ago
Add custom button in Component with form.
FilamentFFilament / ❓┊help
3y ago