© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•9mo ago•
3 replies
bernhard

Modal Action halt and autofocus

I have a modal action with one input field. When opening the modal, it should autofocus this input. After the action is done, it should reset the form and autofocus the input again.

With
$form->fill()
$form->fill()
and
$action->halt()
$action->halt()
I can clear the form and keep it open, but the input isn't autofocused?

Action::make('einbuchen')
    ->form([
        TextInput::make('code')
            ->autofocus()
            ->required()
    ])
    ->action(function (array $data, self $livewire, Action $action, Form $form) {
        // custom logic...
        // ...
        $form->fill();
        $action->halt();
    })
Action::make('einbuchen')
    ->form([
        TextInput::make('code')
            ->autofocus()
            ->required()
    ])
    ->action(function (array $data, self $livewire, Action $action, Form $form) {
        // custom logic...
        // ...
        $form->fill();
        $action->halt();
    })
Solution
try this

->action(function (array $data, self $livewire, Action $action, Form $form) {
    $form->fill();
    $livewire->js("document.getElementById('{$form->getStatePath()}.code').focus()");
    $action->halt();
}),
->action(function (array $data, self $livewire, Action $action, Form $form) {
    $form->fill();
    $livewire->js("document.getElementById('{$form->getStatePath()}.code').focus()");
    $action->halt();
}),
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

Halt modal action
FilamentFFilament / ❓┊help
3y ago
Autofocus in a Modal
FilamentFFilament / ❓┊help
3y ago
Modal action
FilamentFFilament / ❓┊help
2y ago
ToggleColumn and Modal Confirmation (Action?)
FilamentFFilament / ❓┊help
3y ago