Mark
Mark
FFilament
Created by Mark on 11/21/2024 in #❓┊help
How can I access component properties in view?
I'm trying to create a custom field using the following code:
<?php

namespace App\Forms\Components;

use Filament\Forms\Components\Field;

class SelectWithPivot extends Field
{
protected string $view = 'forms.components.select-with-pivot';

public ?int $selectedItem = null;

protected function setUp(): void
{
parent::setUp();

$this->afterStateHydrated(function (self $component, ?array $state) {
if (blank($state)) {
$component->state(['test' => 1]);
}
});
}

public function updatedSelectedItem()
{
dd($this->selectedItem);
}
}
<?php

namespace App\Forms\Components;

use Filament\Forms\Components\Field;

class SelectWithPivot extends Field
{
protected string $view = 'forms.components.select-with-pivot';

public ?int $selectedItem = null;

protected function setUp(): void
{
parent::setUp();

$this->afterStateHydrated(function (self $component, ?array $state) {
if (blank($state)) {
$component->state(['test' => 1]);
}
});
}

public function updatedSelectedItem()
{
dd($this->selectedItem);
}
}
Now I want to use the $selectedItem property in my blade (wire:model):
<x-dynamic-component
:component="$getFieldWrapperView()"
:field="$field"
>
{{ json_encode($getState()) }}
<div x-data="{ state: $wire.{{ $applyStateBindingModifiers("\$entangle('{$getStatePath()}')") }} }">
<select wire:model="selectedItem">
<option>1</option>
<option>2</option>
<option>3</option>
</select>
</div>
</x-dynamic-component>
<x-dynamic-component
:component="$getFieldWrapperView()"
:field="$field"
>
{{ json_encode($getState()) }}
<div x-data="{ state: $wire.{{ $applyStateBindingModifiers("\$entangle('{$getStatePath()}')") }} }">
<select wire:model="selectedItem">
<option>1</option>
<option>2</option>
<option>3</option>
</select>
</div>
</x-dynamic-component>
But I get this error: Livewire: [wire:model="selectedItem"] property does not exist on component: [app.domains.relations.filament.resources.relation-resrouce.relation-managers.packages-relation-manager] What am I doing wrong? It seems the view is looking at the parent component or something?
5 replies
FFilament
Created by Mark on 4/25/2024 in #❓┊help
Generating slug from title example only working properly when adding debounce
I'm using this example code: https://filamentphp.com/docs/3.x/forms/advanced#generating-a-slug-from-a-title When I keep typing in the title field it cannot keep up, when I type something like this: This is a very long title, just a few more words to make it longer After a while the input is looking like this: This is a ry long tie, jus a w re worto makit longer When I add debounce or just add two TextInputs for the same property there is no problem and both inputs are updated accordingly. Am I missing something, is this a problem with Filament/Livewire?
5 replies