© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
6 replies
krekas

afterStateUpdated after $set

Is there some way to trigger
afterStateUpdated
afterStateUpdated
after using the
$set
$set
?

protected function getPasswordFormComponent(): Component
    {
        return TextInput::make('password')
            ->live()
            ->label(__('filament-panels::pages/auth/register.form.password.label'))
            ->type(fn (Get $get): string => $get('showPassword') ? 'text' : 'password')
            ->required()
            ->rule(Password::default())
            ->dehydrateStateUsing(fn ($state) => Hash::make($state))
            ->same('passwordConfirmation')
            ->validationAttribute(__('filament-panels::pages/auth/register.form.password.validation_attribute'))
            ->afterStateUpdated(function (string $state, Set $set, Get $get) {
                $set('strengthScore', (new Zxcvbn())->passwordStrength($state)['score']);
            })
            ->hintAction(
                Action::make('generate')
                    ->label('Generate')
                    ->action(function (Set $set) {
                        $password = Str::password(12);
                        $set('password', $password);
                        $set('passwordConfirmation', $password);
                    }),
            );
    }
protected function getPasswordFormComponent(): Component
    {
        return TextInput::make('password')
            ->live()
            ->label(__('filament-panels::pages/auth/register.form.password.label'))
            ->type(fn (Get $get): string => $get('showPassword') ? 'text' : 'password')
            ->required()
            ->rule(Password::default())
            ->dehydrateStateUsing(fn ($state) => Hash::make($state))
            ->same('passwordConfirmation')
            ->validationAttribute(__('filament-panels::pages/auth/register.form.password.validation_attribute'))
            ->afterStateUpdated(function (string $state, Set $set, Get $get) {
                $set('strengthScore', (new Zxcvbn())->passwordStrength($state)['score']);
            })
            ->hintAction(
                Action::make('generate')
                    ->label('Generate')
                    ->action(function (Set $set) {
                        $password = Str::password(12);
                        $set('password', $password);
                        $set('passwordConfirmation', $password);
                    }),
            );
    }
Solution
Why don't you move the
$set('strengthScore...
$set('strengthScore...
into the action?
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Triggering afterStateUpdated() with $set()?
FilamentFFilament / ❓┊help
17mo ago
afterStateUpdated and field changed by $set()
FilamentFFilament / ❓┊help
3y ago
Set the state of ->afterStateUpdated inside a test
FilamentFFilament / ❓┊help
3y ago