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
I had the same issue, found that adding a
->default(0)
to the TableColumn solves the issue:
I tested it but the same issue, I have the following form field:
And the Toggle is always unchecked
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.
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()
and (sorry if this seems like an obvious question) are Title and Subtitle actually pulling data from the array?
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
I dont' see the toggle at all there.
ow sorry, check now
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
yes totally it's weird
So, that tells me that the toggle is getting picked up from something else, and saved to something else, not to the unique record.
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
I reloaded the page
the toggle is still persistent across all records
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
k
What's the reason for using arrays everywhere?
(vs Eloquent models)
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
nice
but you are right with models I will not have this issues
As you say, it's possible that the array stuff isn't loaded/preloaded the same as Eloquent will
thanks for your time and help
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
yes I will check this
Cheers. Best of success!