F
Filament•12mo 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
DarkOP•12mo 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
DarkOP•12mo ago
And the Toggle is always unchecked
No description
DrByte
DrByte•12mo 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
DarkOP•12mo 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
DrByte•12mo ago
and (sorry if this seems like an obvious question) are Title and Subtitle actually pulling data from the array?
Dark
DarkOP•12mo 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 : [email protected] - password : secret
DrByte
DrByte•12mo ago
I dont' see the toggle at all there.
DrByte
DrByte•12mo ago
No description
Dark
DarkOP•12mo ago
ow sorry, check now
DrByte
DrByte•12mo 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
DarkOP•12mo ago
yes totally it's weird
DrByte
DrByte•12mo 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
DarkOP•12mo 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
DrByte•12mo ago
I reloaded the page the toggle is still persistent across all records
Dark
DarkOP•12mo 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
DrByte•12mo ago
k What's the reason for using arrays everywhere? (vs Eloquent models)
Dark
DarkOP•12mo 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
DrByte•12mo ago
nice
Dark
DarkOP•12mo ago
but you are right with models I will not have this issues
DrByte
DrByte•12mo ago
As you say, it's possible that the array stuff isn't loaded/preloaded the same as Eloquent will
Dark
DarkOP•12mo ago
thanks for your time and help
DrByte
DrByte•12mo 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
DarkOP•12mo ago
yes I will check this
DrByte
DrByte•12mo ago
Cheers. Best of success!
Want results from more Discord servers?
Add your server