F
Filament2mo ago
nowak

Dynamic selectablePlaceholder closure does not have the desired effect

I have a select field, that I want to not show the selectablePlaceholder "x" icon, on specific conditions, which depend on the state of other fields in my form. When I use ->selectablePlaceholder(false) , the "x" icon is removed as expected, but when I use this:
->selectablePlaceholder(function (Get $get, ?string $state) {
$groupId = (int) ($get('group_id') ?? 0);
if ($groupId) {
$singleUsers = User::query()
->whereHas('groups', fn($q) => $q->whereKey($groupId))
->limit(2)
->get();
if (count($singleUsers) === 1 && $singleUsers->contains('id', $state)) {
return false;
}
}
return true;
})
->selectablePlaceholder(function (Get $get, ?string $state) {
$groupId = (int) ($get('group_id') ?? 0);
if ($groupId) {
$singleUsers = User::query()
->whereHas('groups', fn($q) => $q->whereKey($groupId))
->limit(2)
->get();
if (count($singleUsers) === 1 && $singleUsers->contains('id', $state)) {
return false;
}
}
return true;
})
whenever the closure returns false , the selectablePlaceholder "x" icon is still visible which is not expected, and whenever the closure returns true, the selectablePlaceholder "x" icon is visible as expected. Is selectablePlaceholder not meant to be dynamic? I.e. does it only set the selectablePlaceholder icon on first render/mount, or can it be set dynamically?
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?