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() and $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 ```php ->action(function (array $data, self $livewire, Action $action, Form $form) { $form->fill();...
Jump to solution
2 Replies
Solution
LeandroFerreira
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();
}),
bernhard
bernhardOP4d ago
Thanks! Thats exactly what I was looking for !

Did you find this page helpful?