FilamentF
Filament5mo ago
Roland

Refresh Modal form on Custom component

Hey Everyone,

I have a custom component on the left which one is shown by Render hooks. That works.

I click on one of the avatars, it shows a modal. On the modal I want to create ToggleButtons based on which avatar i choose, but it doesn't work. (Customer - Projects 1-n relation)

After i choose the avatar and store the data in $this->projects, the form doesn't refill.

If a remove #[Renderless] it still doesn't work. It's needed because without it livewire throw snapshot error.

CustomerSwithcer Livewire component:

class CustomerSwitcher extends Component implements HasSchemas
{
use InteractsWithSchemas;

public $customers;

public $projects;

public $selectedProjectId;

public function mount()
{
$this->customers = Auth::user()->customers()->pluck('name', 'customer_id');
}

#[Renderless]
public function openProjectModal($id)
{
$this->selectedProjectId = $id;

$customer = Customer::with('projects')->find($id);
$this->projects = $customer->projects
->mapWithKeys(fn($p) => [
$p->id => $p->name . ' - ' . $p->part_number
])
->toArray();


$this->dispatch('open-modal', id: 'select-project');

}

public function form(Schema $schema): Schema
{
return $schema
->components([
ToggleButtons::make('selectedProjectId')
->label('Projects')
->reactive()
->options(fn () => $this->projects)
]);
}

public function render(): View
{
return view('filament.components.customer-switcher');
}

}

Thanks in advance!
image.png
image.png
Was this page helpful?