How to debounce entangled x-model?
i created a custom field.
this is how i entangle the state:
but like this i cant get the state when i apply
afterStateUpdated
on my filament form field. if i make it like this (without defer), it works:
but obviously i dont want it this way, since im calling an api and dont wanna call it every second, so this is what im trying now:
but it doesnt work
what im doing wrong??
im checking this docs:
https://livewire.laravel.com/docs/wire-model#all-available-modifiers
https://livewire.laravel.com/docs/alpine#sharing-state-using-wireentangle26 Replies
bump
Try this
state: $wire.{{ $applyStateBindingModifiers("entangle('{$statePath}')") }}
i try:
x-data="{ state: $wire.{{ $applyStateBindingModifiers("entangle('{$statePath}')") }} }"
i get:
Object of class Closure could not be converted to string
im on v2
sorryoh.
wrong tag
praying to upgrade the project to v3 but cant yet š¢
state: $wire.{{ $applyStateBindingModifiers('entangle(\'' . $getStatePath() . '\')', lazilyEntangledModifiers: ['defer']) }},
look at the filament form components to see how it is applying things.
that example is from the TextInput in v2i tried to see it in the richeditor idk why but i wasnt lucky finding it
so now, with this change, what i can achieve?
so far doesnt crash
i can use ->reactive() ?
yes
reactive makes the field live
yes, so i can debounce it now i guess, im gonna search how to
probably
->debounce()
instead of ->reactive()
don't fully remember in v2
or ->reactive(debounce: 500)
yeah smth like that
thanks a lot @awcodes š
im keeping it lke this
->debounce(delay: '1000ms')
for now. it works nice.
i may want it to be updated on blur, how would be the walkaround? triyn to find ->onblur or something similari think it's
->lazy()
for blur in v2seems im still doing something wrong. i have it like this now:
i expected the distance field to be updated but it doesnt
x-data is set like this https://discord.com/channels/883083792112300104/1257990350581137448/1258051938851881122
and i also tried to add reactive to 'distance' text input but doesnt make any differecne
if i use debounce(), i still need to use reactive()?
i tried it with and without reactive(), same result
and i tried debounce without param too, but same result
if i remove the debounce, it is live (but i want it to debounce)
and yep, it is
seems ok to me
maybe because distance is disabled? not totally sure.
just checked it, noup
i havent told u something. the state is not being set directly by typing in the input
this is how it works:
user types (for example):
Sagrada Familia
then i call google maps api to get the full place name (Sagrada Familia, street random, Barcelona)
and then i set the state with that new name
so not sure if the debounce is not able to listen to it, cuz maybe debounce is only meant for the input itself, and not the internal x-model value
not sure if i explain myself, let me know plz
do you have spatie Ray?
no
(yet : )
ok, you could try a dd() in afterStateUpdated(), make sure that is getting called.
sometimes dd's don't work in the callbacks though. that's where ray would help. š
i can do
info('inside afterstateupdated')
too i guess, right?maybe?
lol
xddd why lol?
well, yeah it doesnt dd neither log
š¤
can you share your whole blade code?
can i do it via private msg? i dont have any compromised data to share but i prefer to not share the full component here
the blade is nothing special
but yeah š
then we can continue the conversation here for sure if u up to š
that's fine
but it helps to have it here, so other's having the same issue can find a solution.
yeah i know. if someone has the problem and we find a solution, i dont mind to help. for future viewers, ping me if needed xd