filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
19.29k stars 2.96k forks source link

afterStateHydrated not being called on $set #14824

Closed jordanmiguel closed 1 day ago

jordanmiguel commented 1 day ago

Package

filament/filament

Package Version

v3

Laravel Version

v11

Livewire Version

v3

PHP Version

PHP 8.3

Problem description

I'm using https://filamentphp.com/plugins/leandrocfe-brazilian-form-fields to fill out address information based on the zip code. When a zip code is fetched, it updates fields with the zip information.

But for the state_id, I need to hydrate the info (it comes as a CODE, example: NY), and find the state in the DB (State::where('code', $code)->id).

The thing is, when state_id is updated with the CODE using $set, or any other field (if I select other field to be updated), afterStateHydrated is not being called, as well as afterStateUpdated. Both fields already have ->live() attribute.

Expected behavior

afterStateHydrated should be called when $set for the field is called.

Steps to reproduce

  1. Create a field that sets other field value
  2. Try to listen to those changes using afterStateHydrated

Reproduction repository (issue will be closed if this is not valid)

https://github.com/leandrocfe/filament-ptbr-form-fields

Relevant log output

No response

Donate 💰 to fund this issue

Fund with Polar

danharrin commented 1 day ago

This is not the intended behaviour so it's not really a bug, "hydration" is the process of filling the form with predefined/default values and ensuring anything without a value still exists in the state. $set() is a method used for state updates, not hydration. I think in v4 there is an option to call afterStateUpdated() from a $set()