F
Filament2mo ago
Tally

ToggleButtons problem can anyone check if the multiple option is still working?

If you create a simple ToggleButtons field like this
Forms\Components\ToggleButtons::make('test')
->multiple()
->options([
'one', 'two', 'three', 'four', 'five',
]),
Forms\Components\ToggleButtons::make('test')
->multiple()
->options([
'one', 'two', 'three', 'four', 'five',
]),
If I click "two" everything is selected? If I inspect the livewire data... the test is null instead of [] Am I missing something?
13 Replies
Tally
Tally2mo ago
Filament v3.2.83 Laravel Framework 11.8.0
awcodes
awcodes2mo ago
The options need to be an array of value => label
Tally
Tally2mo ago
Hi Adam, Nope sorry not working as well... used the example in the docs to test this
Forms\Components\ToggleButtons::make('test')
->multiple()
->options([
'tailwind' => 'Tailwind CSS',
'alpine' => 'Alpine.js',
'laravel' => 'Laravel',
'livewire' => 'Laravel Livewire',
])
Forms\Components\ToggleButtons::make('test')
->multiple()
->options([
'tailwind' => 'Tailwind CSS',
'alpine' => 'Alpine.js',
'laravel' => 'Laravel',
'livewire' => 'Laravel Livewire',
])
https://filamentphp.com/docs/3.x/forms/fields/toggle-buttons#selecting-multiple-buttons
Tally
Tally2mo ago
No description
awcodes
awcodes2mo ago
Where are you using the component? Ina resource or a standalone livewire component.
Tally
Tally2mo ago
in a resource.. just plain Filament in a test project
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\ToggleButtons::make('test')
->multiple()
->options([
'tailwind' => 'Tailwind CSS',
'alpine' => 'Alpine.js',
'laravel' => 'Laravel',
'livewire' => 'Laravel Livewire',
])
]);
}
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\ToggleButtons::make('test')
->multiple()
->options([
'tailwind' => 'Tailwind CSS',
'alpine' => 'Alpine.js',
'laravel' => 'Laravel',
'livewire' => 'Laravel Livewire',
])
]);
}
awcodes
awcodes2mo ago
Hmm. I haven’t seen any problems with them.
Tally
Tally2mo ago
ok lemme ask a friend to check this in his project...
awcodes
awcodes2mo ago
ok, i'm seeing the same with multiple on v3.2.83. so it's gotta be a bug.
Tally
Tally2mo ago
ok... pfieuw... was driving me mad thanks for checking
awcodes
awcodes2mo ago
no problem. please submit it on GitHub. 🙂
Tally
Tally2mo ago
yes will do you woul not believe it... it works in the testrepo?? asked a friend of mine in his project... also seing the bug ok... narrowed it down... If I use a fieldname that does not exist in the database it works on create... but if you edit a resource it's not working anymore.. I think because it sets the value to null somewhere is there a use case you would use a fieldname which is not in the database? only for advanced purposes I think? is it handy to propose a change in the ToggleButtons field? or first post the bug repo (don't really know if it's a bug... feels like a bug) and then propose a PR with the fix? I changed
protected function setUp(): void
{
parent::setUp();

$this->default(function (ToggleButtons $component): mixed {
return $component->isMultiple() ? [] : null;
});
}
protected function setUp(): void
{
parent::setUp();

$this->default(function (ToggleButtons $component): mixed {
return $component->isMultiple() ? [] : null;
});
}
to
protected function setUp(): void
{
parent::setUp();

$this->afterStateHydrated(static function (ToggleButtons $component, $state): void {
if ($component->isMultiple && is_null($state))
{
$component->state([]);
}
});

$this->default(function (ToggleButtons $component): mixed {
return $component->isMultiple() ? [] : null;
});
}
protected function setUp(): void
{
parent::setUp();

$this->afterStateHydrated(static function (ToggleButtons $component, $state): void {
if ($component->isMultiple && is_null($state))
{
$component->state([]);
}
});

$this->default(function (ToggleButtons $component): mixed {
return $component->isMultiple() ? [] : null;
});
}
so if the value is null and it's a multiple field.. set the state to an empty string
Tally
Tally2mo ago
GitHub
Problem with multiple() in ToggleButtons · Issue #12962 · filamentp...
Package filament/filament Package Version v3.2.83 Laravel Version 11.8.0 Livewire Version No response PHP Version PHP 8.3.3 Problem description If I'm using the example from the docs Forms\Comp...