© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
12 replies
Wirkhof

Execute an action on checkbox toggle

I would like to reset the password and password_confirmation fields when I check or uncheck the checkbox button, so the passwords start from a clean slate all the time.

I am not sure if it can be done via Livewire or Alpine somehow or there is an inbuilt functionality inside Filament.

My code:

Checkbox::make('password_change_checkbox')
    ->label('Change your password')
    ->visibleOn('edit')
    ->live(),

TextInput::make('password')
    ->dehydrated(fn(Get $get): bool => $get('password') != '')
    ->live()
    ->afterStateUpdated(
        function (
          Forms\Contracts\HasForms $livewire, 
          Forms\Components\TextInput $component
        ) {
          $livewire->form->getState();
    })
    ->confirmed()
    ->required()
    ->label('Password') 
    ->visibleOn('edit')
    ->hidden(fn(Get $get): bool => !$get('password_change_checkbox')),

TextInput::make('password_confirmation')
    ->dehydrated(false)
    ->live()
    ->afterStateUpdated(
        function (
          Forms\Contracts\HasForms $livewire, 
          Forms\Components\TextInput $component
        ) {
          $livewire->form->getState();
    })
    ->required()
    ->label('Repeat password') 
    ->visibleOn('edit')
    ->hidden(fn(Get $get): bool => !$get('password_change_checkbox'))
Checkbox::make('password_change_checkbox')
    ->label('Change your password')
    ->visibleOn('edit')
    ->live(),

TextInput::make('password')
    ->dehydrated(fn(Get $get): bool => $get('password') != '')
    ->live()
    ->afterStateUpdated(
        function (
          Forms\Contracts\HasForms $livewire, 
          Forms\Components\TextInput $component
        ) {
          $livewire->form->getState();
    })
    ->confirmed()
    ->required()
    ->label('Password') 
    ->visibleOn('edit')
    ->hidden(fn(Get $get): bool => !$get('password_change_checkbox')),

TextInput::make('password_confirmation')
    ->dehydrated(false)
    ->live()
    ->afterStateUpdated(
        function (
          Forms\Contracts\HasForms $livewire, 
          Forms\Components\TextInput $component
        ) {
          $livewire->form->getState();
    })
    ->required()
    ->label('Repeat password') 
    ->visibleOn('edit')
    ->hidden(fn(Get $get): bool => !$get('password_change_checkbox'))


Perhaps adding afterStateUpdated() to Checkbox::make() ? But how to target password and password_confirmation fields only? And make them clear up both when clicking on the checkbox (for both show and hide states)?
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Align toggle/checkbox
FilamentFFilament / ❓┊help
11mo ago
Checkbox list as Toggle
FilamentFFilament / ❓┊help
3y ago
Execute an action after the default action
FilamentFFilament / ❓┊help
3y ago
custom toggle action
FilamentFFilament / ❓┊help
3y ago