afterStateUpdated() function does not work when hidden() is true

Toggle::make('kismi_teklife_acik_mi') ->live() ->requiredWith('kisim_sayisi') ->inline(false) ->afterStateUpdated(function (Get $get, Set $set) { if (($get('kismi_teklife_acik_mi') == false)) { $set('kisim_sayisi', null); } }) ->label('İhale Kısmi Teklife Açık Mı?'), TextInput::make('kisim_sayisi') ->label('Kısım Sayısı') ->requiredWith('kismi_teklife_acik_mi') ->numeric() ->validationAttribute('Kısım Sayısı') ->hidden( fn (Get $get): bool => !$get('kismi_teklife_acik_mi') ), Hello, I want to empty the kisim_sayisi field when the kismi_teklife_acik_mi field is closed. If it is visible, it works, but if it is not visible, it does not assign null. In short, afterStateUpdated() does not work when hidden() is true.
4 Replies
toeknee
toeknee6mo ago
This is correct! Hidden fields are removed from the request as they are no longer part of it. What you should do, is mutate the data before saving or creating to null it if that field is true. This prevents people manipluating the data in the browser.
Fatih Durmaz
Fatih Durmaz6mo ago
How can I empty the area before it is hidden?
toeknee
toeknee6mo ago
Just mutate it on the save?
Fatih Durmaz
Fatih Durmaz6mo ago
Yes, this might work for me too.
Want results from more Discord servers?
Add your server