Revert togglecolumn $state if condition unsatisfied.
I have togglecolumn on table. when
if the togglecolumn is currently false, when toggle from false to true, if the condition didn't meet, the toggle stay at false.
the problem is
if the togglecolumn is currently true, when toggle from true to false, if the condition didnt meet, the toggle will still move to false. if refresh the page, the toggle will show true again. I supposed it should stay at true instead of going to false?
Any hints or guidance would be greatly appreciated!
9 Replies
What are you trying to do here, prevent non-admins from switching the toggle?
Why not just disable it?
yes, and other condition as well. not necessary non-admins
is disabled a better choice in this case?
I mean its all up to you, but you can do
->disabled(fn() => auth()->user()->hasRole('admin'))
because the above code able to prevent toggle from false to true, but not able to prevent the opposite.
and I want to run notification as well. if disabled, can we set notification like below? I think it would become more complex isnt it?
Im not sure if you can exactly "halt" it 🤔
I guess you could use
beforeStateUpdated
to display a notication and afterStateUpdated
to revert it back but this is not a good fix...If you're doing sometihng complex, I would use an action modal, you'll have better control anyway.
Table record adjustments.....🤮
can you confirm on your side it is same behaviour as well? is this consider an issue to be submitted on github?
Notifications work for me.
Just the resetting doesn't work 😛
Disabling the option would be easier imo.