#onBlur on TextInput prevent afterStateUpdated to launch

41 messages · Page 1 of 1 (latest)

cunning veldt
#

Learning how to use Filament through a Filament 5 Laracast course, I just stumbled on an issue trying to replicate what the tutor said...
I got this issue with the code here :

TextInput::make('effort_in_days')
  ->required()
  ->numeric()
  ->live(onBlur: true)
  ->afterStateUpdated(function ($state, Set $set, Get $get) {
    $set('cost', ($get('is_high_cost') ? 1500 : 1000) * $state);
  })
  ->default(0),

The ->afterStateUpdated is never launched when the field is blurred, left by switching to another field or not selecting one at all. If I just set a plain ->live() or I put a debounce value, it's working perfectly, but not with the onBlur. Did I miss something there, is it intended or is it an issue related to something else? In any case, in the course I am following, it's working but it was on Filament 5.0 beta.

Thank you for your help in this mater.

ripe canyonBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

cunning veldt
#

I did try with

->afterStateUpdatedJs(<<<'JS'
  const isHighCost = $get('is_high_cost')
  const effort = $state
  const costPerDay = isHighCost ? 1500 : 1000
  $set('cost', effort * costPerDay)
JS),
#

And it's even worse, as there is no javascript executed at all? I don't understand what's wrong... missing assets? Issue with vite compilation? Really strange.

foggy sand
#

Code looks ok to me. Is this on a fresh install or an upgraded app?

cunning veldt
#

It does just nothing. But I find the js in the inspector.

#

So it's something else that is interfering.

foggy sand
#

Can you try it in another fresh install and if you can replicate it please submit an issue. It could be a bug with a recent release.

#

Maybe share the whole form schema in a gist too, it’s hard to know for sure with just seeing the code for one field.

cunning veldt
cunning veldt
#

Thanks

#

@foggy sand to your knowledge and I don't see a reason why. But could it be related to the use of PHP 8.2 rather than a newer version ?

foggy sand
#

I don’t think so.

cunning veldt
#

Or a missing extension maybe. But i don't see why either.

#

I'll try it in a docker tomorrow as well

#

Could just be my test environment which is faulty...

foggy sand
#

It could be that the path to the property in get or set could be off but can’t know that without seeing the whole schema.

cunning veldt
#

Yeah will check that tomorrow

foggy sand
cunning veldt
#

Yeah

#

But I think the JS version not working and the onBlur are related

#

It's like there no JS working on the client side as it should

foggy sand
#

Yea, could even be something in livewire, unrelated to filament.

cunning veldt
#

Yeah my thought exactly

foggy sand
#

Do you have SPA mode enabled in the panel provider?

cunning veldt
#

No

foggy sand
#

Ok. Just checking. Any console errors?

cunning veldt
#

None

#

(first thing I checked)

foggy sand
#

Ok, yea try the fresh install tomorrow and let us know.

#

Go to sleep. 😂

cunning veldt
#

Sure I'll do that. It will bother me otherwise

#

I have a current project for a customer I want to upgrade to latest filament

foggy sand
#

We’re certainly here to help but we need more info.

cunning veldt
cunning veldt
#

Should I update anything aside of the assets after updating ?

ripe canyonBOT
foggy sand
#

Unless you have a custom theme the assists should be enough. Filament should have added the assets command to composer.json for you.