Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

raobilal4822's avatar

Custom Filament field live() and other functions are not working

i have create a custom filament form field

0 likes
1 reply
LaryAI's avatar
Level 58

Certainly! The issue here is that when you create a custom Filament field, you need to ensure that your custom field class and Blade view are properly integrated with Filament’s lifecycle and event system. Specifically, for methods like live(), reactive(), and callbacks like afterStateUpdated(), Filament expects your field to emit and handle state changes in a specific way.

Why live() and afterStateUpdated() Aren't Working

  • Filament’s built-in fields automatically handle Livewire state updates and lifecycle hooks.
  • Custom fields must manually wire up these hooks and ensure that state changes in Alpine/Livewire are properly communicated back to Filament.

Common Issues:

  1. Not using Filament's field state management helpers in your Blade view.
  2. Not triggering the correct Livewire events when the state changes.
  3. Not using the correct Alpine/Livewire entanglement.

Solution

1. Use Filament’s Provided Alpine State Helpers

Filament provides $applyStateBindingModifiers() and $getStatePath() to help with state binding. You should use these in your Blade view.

Update your Alpine data binding like this:

x-data="{}"
x-init="window.addEventListener('filament.forms::field-state-updated', event => {
    if (event.detail.statePath === '{{ $getStatePath() }}') {
        state = event.detail.state;
    }
})"

But Filament provides a helper for this. The best practice is:

x-data="{}"
x-model{{ $applyStateBindingModifiers('state') }}="{{ $getStatePath() }}"

But since you’re using a custom field, you should use the $wire.entangle() helper with modifiers:

x-data="{
    state: $wire.entangle('{{ $getStatePath() }}'){{ $applyStateBindingModifiers('') }},
}"

2. Update State via Livewire

When you update the state in Alpine, you must ensure it updates the Livewire property so Filament can trigger afterStateUpdated().

Change this:

x-on:click="state = '{{ $value }}'"

To this:

x-on:click="state = '{{ $value }}'"

This is correct, but you must ensure that state is entangled with Livewire with the correct modifiers.

3. Use $applyStateBindingModifiers()

In your Blade, update the Alpine data definition:

<div
    x-data="{
        state: $wire.entangle('{{ $getStatePath() }}'){{ $applyStateBindingModifiers('') }},
    }"
>

4. Use x-model for Two-way Binding

Instead of manually setting state, use x-model for two-way binding:

<div
    x-data="{
        state: $wire.entangle('{{ $getStatePath() }}'){{ $applyStateBindingModifiers('') }},
    }"
>
    <div
        x-on:click="state = '{{ $value }}'"
        :class="state === '{{ $value }}' ? 'ring-2 ring-primary-600 bg-primary-50 dark:bg-primary-500/10' : 'ring-1 ring-gray-300 dark:ring-gray-700 hover:ring-primary-500'"
        class="relative flex flex-col items-center justify-center p-4 text-center transition-all duration-200 cursor-pointer"
    >
        ...
    </div>
</div>

5. Ensure Your Field Extends the Correct Filament Class

Your custom field class should extend Filament\Forms\Components\Field (or similar), not just a plain class.


Example: Corrected Blade View


Summary Checklist

  • Use $wire.entangle('{{ $getStatePath() }}'){{ $applyStateBindingModifiers('') }} for Alpine state.
  • Use x-model or update the entangled state to trigger Livewire updates.
  • Ensure your field class extends the correct Filament base class.
  • Use Filament’s state binding helpers in your Blade view.

Reference


If you follow the above, your live(), reactive(), and afterStateUpdated() callbacks will work as expected!

Please or to participate in this conversation.