F
Filament16mo ago
krekas

afterStateUpdated after $set

Is there some way to trigger afterStateUpdated after using the $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... into the action?
Jump to solution
4 Replies
Solution
josef
josef16mo ago
Why don't you move the $set('strengthScore... into the action?
krekas
krekasOP16mo ago
yeah i just thought about that also lol
josef
josef16mo ago
@Dennis Koch ?
Dennis Koch
Dennis Koch16mo ago
⚠️ Warning. Don't provide good answers 😅 Sorry, hit the wrong emoji
Want results from more Discord servers?
Add your server