F
Filament10mo ago
Wirkhof

How to save the value of hidden toggle?

I have two toggles. If the first one is on, it will show the second toggle. If the frist one is off, it will hide the second toggle. I am using this on the first toggle to set the value to off when offing the first toggle:
->afterStateUpdated(function (Set $set, $state) {
if ($state === false) {
$set('second_thing', false);
}
})
->afterStateUpdated(function (Set $set, $state) {
if ($state === false) {
$set('second_thing', false);
}
})
The problem is that while it seems to be working in the form visually, it is not saving the state of the second toggle (second_thing) in the DB, just the first toggle is saved correctly. As if the afterStateUpdated doesn't propagate to the save method? Because if I manually (click with the mouse) on the second toggle directly to the state I want and press save - it is saved correctly. How to alter the afterstateupdated method (or use something else) to save it correctly?
3 Replies
Wirkhof
WirkhofOP10mo ago
I am reading this in docs:
Only changes from the user on the frontend will trigger this function, not manual changes to the state from $set() or another PHP function.
Still have no idea how to make it save the programatically changed value.
Wirkhof
WirkhofOP10mo ago
Thanks, it seems I will have to do it like this. It's more code but it works. Thanks.
Want results from more Discord servers?
Add your server