F
Filament6mo ago
Dark

Toggle always false

Using array as the form values, I have a Toggle input, but the toggle is always false, when debugging I have the correct value (true) in my array but the toggle is always false (unchecked). any idea?
25 Replies
🤖transistor🤖
I had the same issue, found that adding a ->default(0) to the TableColumn solves the issue:
Tables\Columns\IconColumn::make('email_verified_at')
->default(0)
Tables\Columns\IconColumn::make('email_verified_at')
->default(0)
Dark
Dark6mo ago
I tested it but the same issue, I have the following form field:
// ...
$record['extra_3'] = true;
// ...
Toggle::make('record.extra_3')->label('Extra input 3')
// ...
$record['extra_3'] = true;
// ...
Toggle::make('record.extra_3')->label('Extra input 3')
Dark
Dark6mo ago
And the Toggle is always unchecked
No description
DrByte
DrByte6mo ago
if the toggle is unchecked then it means it's not receiving a truthy value ... which means you've probably passed an incorrect field or incorrect data to it. It would help if you post the complete code of your form.
Dark
Dark6mo ago
here is the form code https://github.com/heloufir/filament-kanban-demo/blob/main/CustomFormDemo.php and data used into the form is an array https://github.com/heloufir/filament-kanban-demo/blob/main/KanbanService.php look to the method getRecordsWithExtra()
DrByte
DrByte6mo ago
and (sorry if this seems like an obvious question) are Title and Subtitle actually pulling data from the array?
Dark
Dark6mo ago
yes all fields are correct and if I change Toggle with Checkbox it works correctly you can check the demo online here : https://filament-kanban.heloufir.dev/admin/demo/custom-form Use account: - email : john.doe@gmail.com - password : secret
DrByte
DrByte6mo ago
I dont' see the toggle at all there.
DrByte
DrByte6mo ago
No description
Dark
Dark6mo ago
ow sorry, check now
DrByte
DrByte6mo ago
okay, it's showing now If I toggle it to true and Submit, then it's created a new identical record. And now every record I open in any column also now has the toggle checked
Dark
Dark6mo ago
yes totally it's weird
DrByte
DrByte6mo ago
So, that tells me that the toggle is getting picked up from something else, and saved to something else, not to the unique record.
Dark
Dark6mo ago
ow, I see in the console this error Livewire Entangle Error: Livewire property ['record.extra_3'] cannot be found on component: ['app.filament.pages.custom-form-demo'] so I added this to the form field ->visible(fn () => isset($this->record['extra_3'])) and now it is working you can check the demo now
DrByte
DrByte6mo ago
I reloaded the page the toggle is still persistent across all records
Dark
Dark6mo ago
yes because I set it to true everywhere except the Record 1 col 1 so I think when launching the page the field is not loaded yet
DrByte
DrByte6mo ago
k What's the reason for using arrays everywhere? (vs Eloquent models)
Dark
Dark6mo ago
because I have the public array $record = []; it's a package that I developped to make it simple without models but working on a version using models 🙂 so you can use models or arrays as you want
DrByte
DrByte6mo ago
nice
Dark
Dark6mo ago
but you are right with models I will not have this issues
DrByte
DrByte6mo ago
As you say, it's possible that the array stuff isn't loaded/preloaded the same as Eloquent will
Dark
Dark6mo ago
thanks for your time and help
DrByte
DrByte6mo ago
Maybe there are Eloquent hooks you can clone for array stuff, to avoid having to use closures in each field to load up the data
Dark
Dark6mo ago
yes I will check this
DrByte
DrByte6mo ago
Cheers. Best of success!