krekas
get updated property value in view form field
In the simple page I have a public property
But how to get
public int $strengthScore = 0;
I set it using the $set
method.
TextInput::make('password')
->live()
// other rules
->hintAction(
Action::make('generate')
->label('Generate')
->action(function (Set $set, Get $get) {
$password = Str::password(12);
$set('password', $password);
$set('passwordConfirmation', $password);
$set('strengthScore', (new Zxcvbn())->passwordStrength($password)['score']);
}),
);
TextInput::make('password')
->live()
// other rules
->hintAction(
Action::make('generate')
->label('Generate')
->action(function (Set $set, Get $get) {
$password = Str::password(12);
$set('password', $password);
$set('passwordConfirmation', $password);
$set('strengthScore', (new Zxcvbn())->passwordStrength($password)['score']);
}),
);
strengthScore
value in the ViewField after it is updated?
Tried $wire.$entangle
in the x-data
but it get only the initial value.
<div x-data="{ strengthScore: $wire.$entangle('strengthScore', live = true) }">
<progress value="{{ $this->strengthScore }}" max="4" class="w-full"></progress>
</div>
<div x-data="{ strengthScore: $wire.$entangle('strengthScore', live = true) }">
<progress value="{{ $this->strengthScore }}" max="4" class="w-full"></progress>
</div>
10 replies
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);
}),
);
}
7 replies
Multiple forms in custom page
I have two forms. But when pressing submit both forms get's triggered.
class EditProfile extends Page implements HasForms
{
public ?array $profileData = [];
public ?array $passwordData = [];
protected function getForms(): array
{
return [
'editProfileForm',
'editPasswordForm',
];
}
public function editProfileForm(Form $form): Form
{
profile form
}
public function editPasswordForm(Form $form): Form
{
password form
}
public function updateProfile(): void
{
update profile login
}
public function updatePassword(): void
{
update password logic
}
protected function getUpdateProfileFormActions(): array
{
return [
Action::make('updateProfileAction')
->label(__('filament-panels::pages/auth/edit-profile.form.actions.save.label'))
->submit('updateProfile'),
];
}
protected function getUpdatePasswordFormActions(): array
{
return [
Action::make('updatePasswordAction')
->label(__('filament-panels::pages/auth/edit-profile.form.actions.save.label'))
->submit('updatePassword'),
];
}
}
class EditProfile extends Page implements HasForms
{
public ?array $profileData = [];
public ?array $passwordData = [];
protected function getForms(): array
{
return [
'editProfileForm',
'editPasswordForm',
];
}
public function editProfileForm(Form $form): Form
{
profile form
}
public function editPasswordForm(Form $form): Form
{
password form
}
public function updateProfile(): void
{
update profile login
}
public function updatePassword(): void
{
update password logic
}
protected function getUpdateProfileFormActions(): array
{
return [
Action::make('updateProfileAction')
->label(__('filament-panels::pages/auth/edit-profile.form.actions.save.label'))
->submit('updateProfile'),
];
}
protected function getUpdatePasswordFormActions(): array
{
return [
Action::make('updatePasswordAction')
->label(__('filament-panels::pages/auth/edit-profile.form.actions.save.label'))
->submit('updatePassword'),
];
}
}
45 replies