Force select value based on a toggle option

I have a select value with three possible values (0 ,1, 2) ,next to it I've a toggle, when the toggle is true, the select value must be 2. So on my Toggle I'm using ->reactive()->afterStateUpdated( to update the select value, and on my select I'm using disabled(fn ($get) => $get('my_toggle') === true). The problem is that now the select values does not gets submitted, so the value is never updated. Is there a "pretty" way to do it ? As there's no readonly method on Select. I could use a hidden field, and update it, but looks messy. Thnx for your help!
Solution:
ssooo
->disableOptionWhen(fn (string $value, $get): bool => ($get('my_toggle') === true && $value !== '2'))
->disableOptionWhen(fn (string $value, $get): bool => ($get('my_toggle') === true && $value !== '2'))
...
Jump to solution
3 Replies
toeknee
toeknee5d ago
Just do disableOptionWhen 🙂 for the other two options
Solution
toeknee
toeknee5d ago
ssooo
->disableOptionWhen(fn (string $value, $get): bool => ($get('my_toggle') === true && $value !== '2'))
->disableOptionWhen(fn (string $value, $get): bool => ($get('my_toggle') === true && $value !== '2'))
Alberto
AlbertoOP5d ago
Thnxxx!!!

Did you find this page helpful?