F
FilamentWirkhof

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?
W
Wirkhof44d 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.
W
Wirkhof44d 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
More Posts
Show date to frontend, but save anotherWhat would be the best way to show data to the frontend, but save something different to the db? I aOverride `getColors()` from enum for toggle buttonsHi all. I'm using an enum in 2 places: a badge column and a toggle button. The badges need to usimage not loading but accessible via URLHi am uploading an image and i also run php artisan storage:link and still image is not loading thishiddenOn returns an error when creating a resourceSo, on my app I had to add creation of whitelists. Before that you could only view the resource, yousave repeater values as json to DBhello i have a repeater which post the value as an array and when i try to insert data i got > `ArraHow close filament modal in custom page```php <x-filament::modal id='custom-modal-handle'> <x-slot name='header'>Tambah Nominal</x-slotBackgrounds plugin by SWISI try to use this plugin by SWIS https://filamentphp.com/plugins/swisnl-backgrounds#remember which iGroup By in tablePlease is it possible for the id to be starting from 1 in each groupingproblem with customized searchable text columnhttps://filamentphp.com/docs/2.x/tables/columns/getting-started#searching Does anyone know the corrSave relationship first before creating modelSo I need to save the relationship first then create a model and sync itCalculate Totals in the footer for a table componentHow can calculate the total balance of the customers and show it in the footer .Note this table compFilter using columnsHello, I'm having difficulty creating a filter in a query that I inserted in the columns. How can I Hiring a senior mobile app developer from India or PakistanI have some mobile projects. I want someone have over 3 years experience. And especially I hope reacGet current row record in custom action```php Tables\Actions\Action::make('make_additional_payment') ->label('Наплати д