Can you customise the behaviour of a toggle component?
Is it possible to customise the behaviour of a toggle component in the form builder? When I toggle it I want to execute some arbitrary code.
32 Replies
I think I should mention that this toggle isn't linked to any field whatsoever. I tried
afterStateUpdated
but that didn't work, I assume for the reason that it isn't linked to any field so there was technically nothing to update.Solution
afterStateUpdated
works, but i think you need to make your field live
😜Thank you, this seems to work! Would you also happen to know why my explictly defined
default
value isn't being displayed?
I pass in a closure to the default callCode?
wait I'll send more
What field
it's on a toggle, that is not bound to any field on the model
try to set the default to true and then try false, and see if that works.
if that works your other logic is wrong 😛
I tried just returning
true
from the closure but it didn't do anything
i.e. Is this on a edit field or create.
maybe you just can't use a closure
page *
currently on an edit page
Default only works on create 😛
😭 oh
yeah that makes sense actually
Yea its already set at that point
I tried using
->state
for this before but I just kept getting the error
is it actually possible?Mmm
->afterStateHydrated()
maybe?Maybe, but i don't see the logic 😛
Dennis already solved this part, I just had to add
live
to it.
hmmmIf should probably do that part in the edit
and perhaps something else on create?
Not sure what you trying to do.
basically just trying to change the initial state of the toggle column, since it isn't bound to a field of any model
I have no doubt that what I'm trying to do; I'm doing it wrong, but at this point I just want it to work 😭
You want to show a field if that is toggled?
but you don't want to save that toggle field.
Might wanna take a look at:
in combination with dehydrated
Not really, basically the toggle basically just serves as an action, but on the edit page in the form of a toggle. The toggle is not bound to a field on the model but instead gets it's state and action from arbitrary code in closures.
idk how to explain it really
I'll try this
I thought the other person suggested this for the first problem I had
you could probably use the
mount
too if you just want to set the fields value
untested and probably not what you want ^_^afterStateHydrated
actually works, but now yet another problem arises. As I said before I don't want to save the aaa
field. How do I exclude it from the data? It's only purpose is basically executing some arbitrary code.->dehydrated(false)
man, you guys are too smart
it works
thank you so much, both of you @dissto & @CodeWithDennis
👍🏽
Yw 🙂
(I marked the solution to the original question)