Stemonte
Stemonte
FFilament
Created by Stemonte on 1/7/2024 in #❓┊help
Custom field with livewire, is it possible?
Hello, I was wondering if it's possible to create a custom field using Livewire? I've attempted a test, and despite everything appearing to be configured correctly, in the end, the field doesn't get saved for that statePath. My requirement is to build an image selection component to use within various forms for different entities, displaying all media with pagination (similar to the media library). Here's a simplified version of the process I've tried:
Copy code
use Filament\Forms\Components\Component;

class CustomField extends Component {
protected string $view = 'custom-field';
}
Copy code
use Filament\Forms\Components\Component;

class CustomField extends Component {
protected string $view = 'custom-field';
}
The blade file is:
Copy code
<x-dynamic-component
:component="$getFieldWrapperView()"
:field="$field"
>
<livewire:custom-field :state_path="$getStatePath()"></livewire:custom-field>

</x-dynamic-component>
Copy code
<x-dynamic-component
:component="$getFieldWrapperView()"
:field="$field"
>
<livewire:custom-field :state_path="$getStatePath()"></livewire:custom-field>

</x-dynamic-component>
Copy code
use Livewire\Component;

class CustomField extends Component
{
public string $state_path = '';

public function render()
{
return view('custom-field-livewire');
}
}
Copy code
use Livewire\Component;

class CustomField extends Component
{
public string $state_path = '';

public function render()
{
return view('custom-field-livewire');
}
}
And the blade for custom-field-livewire is:
Copy code
@php
$id = uniqid();
@endphp

<input
id=""
name="{{ $id }}"
type="radio"
value="{{ $media->id }}"
wire:loading.attr="disabled"
class="hidden peer media-picker-input"
wire:model="{{ $state_path }}"
/>
Copy code
@php
$id = uniqid();
@endphp

<input
id=""
name="{{ $id }}"
type="radio"
value="{{ $media->id }}"
wire:loading.attr="disabled"
class="hidden peer media-picker-input"
wire:model="{{ $state_path }}"
/>
If you have any insights into why the field isn't getting saved for the specified statePath, I would greatly appreciate your assistance.
2 replies