Using both afterStateUpdated AND afterStateUpdatedJs
Here, the php one doesn't work.
Or maybe it's immediately updated with the JS one?
27 Replies
Dan and Dennis seems to say it should work so I guess the JS is overriding the state update made by Livewire on field blur...
Makes sense, the js isn’t going to wait for a blur if I’m thinking about it correctly.
Now I'm even more confused 😄
if
the js isn’t going to wait for a blurthen Livewire should take control when I blur the field?
I’m just thinking with live() they are both going to run, possibly creating a race condition. Not sure though. Listen to Dan or Dennis before trusting me. 😂
Just saying the whole point of updatedJs is so it doesn’t need to go to the backend with a livewire request.
If anybody wants to reproduce, here is my full code:
Here's the code I have in
\App\Support\SlugGenerator.php
:
And here is my form:
sure! Here I was trying to have super snappy field update + check the DB for duplicates and add my-slug-2
when needed
I'll try to see if it could be a race conditionI wonder if the problem is using a php class/method instead of the JS heredoc directly?
I don't think so because they work independently fine.
And the JS one works very well
Hmm, ok, yea then I’d say both are trying to run
What exactly is the use cases for using both?
Here I was trying to have super snappy field update + check the DB for duplicates and add my-slug-2 when needed
I don’t see how that’s possible with JS since it requires a connection to the db.
Of course
I think for this use case you would need to forego the updatedJs
Or do the DB stuff before save
btw, I'm not looking for a workaround 🙂 I was just wondering why and how it couldn't work
Could potentially do something to automatically change it in dehydrate state to force it, then just have a validation rule if they try to change it after it’s created.
But uniqueness, in my mind, is a validation issue.
Well, in my mind it won’t work because it’s trying to use js to check against something that requires the server, so going through livewire instead of js makes the most sense despite implied speed.
I’m sure Dan and Dennis know something I don’t though.
I believe the issue is
isLive: <?= Js::from($schemaComponent->isLive()) ?>
inside filamentSchemaComponent
, because it doesn't check for onBlur
, even when you set ->live(onBlur: true)
in the component
let me know if you want a workaround ✌️
thanks @LeandroFerreira but that's the Livewire method which doesn't trigger, not the JS one
you mean,
afterStateUpdated
isn't working with live(onBlur: true`?afterStateUpdated
doesn't work on blur when I have afterStateUpdatedJS
.
possibly a race conditionwhat happens?
it works fine.
Let me find what's the problem in my code...
The problem is with
$set()
I think:
With this code, I'm not able to set "backend" in slug field on blur eventdd state, what happens?
It triggers the dd on each change, not on blur
I think blur is trigged within watch inside updatedJs, which I believe is causing the conflict..
because
->live()
enables isLive: true
it should be false if we are using onBlur
I thinkmakes total sense
I tried to add this:
It fixes the
dd()
on change, but doesn't fixes the $set()
from livewire on blur
I'll PR this change though (do you agree?)GitHub
fix: afterStateUpdatedJS live when onBlur:true by CharlieEtienne ·...
Description
On this code, dd() shouldn&#39;t be triggered each time the input changes, only on blur. This PR aims to fix it.
TextInput::make(&#39;title&#39;)
-&gt;afterStateUpda...
take a look
I think the blur event works, but the watch inside the updatedJs overrides the current value
it will reproduce
isLive: false