autofocus() not working

Hello, I have this on a resource class:
public static function form(Form $form): Form
{
return $form
->schema([
TextInput::make('title')->required()->maxLength(255)->autofocus(),
Hidden::make('owner_id')->default(auth()->id()),
]);
}
public static function form(Form $form): Form
{
return $form
->schema([
TextInput::make('title')->required()->maxLength(255)->autofocus(),
Hidden::make('owner_id')->default(auth()->id()),
]);
}
I have a page action on the list resource page for creating new resources that uses the pre-defined CreateAction class. could that be preventing it? let me know if you need more info, cheers.
1 Reply
backtrackjack
backtrackjack11mo ago
both create and edit actions produce modal forms as intended, just the autofocus isn't focusing My solution on a custom component that uses filament forms is this:
//in form schema
TextInput::make('...')
->extraAlpineAttributes([
'x-ref' => 'input',
'@focus-input.window' => '$nextTick(() => { $refs.input.focus(); } )',
])

//callback of action button
public function doAction()
{
//perform action
//...
$this->dispatchBrowserEvent('focus-input');
}
//in form schema
TextInput::make('...')
->extraAlpineAttributes([
'x-ref' => 'input',
'@focus-input.window' => '$nextTick(() => { $refs.input.focus(); } )',
])

//callback of action button
public function doAction()
{
//perform action
//...
$this->dispatchBrowserEvent('focus-input');
}
however trying to do it on a panel page doesn't seem to work the same way. I feel like it has something to do with the lifecycle hooks timing?
class ListMatters extends ListRecords
{
protected static string $resource = MatterResource::class;

protected function getActions(): array
{
return [
Actions\CreateAction::make()
->disableCreateAnother()
->afterFormFilled(function() {
$this->dispatchBrowserEvent('focus-matter-title-input');
})
->after(fn (Model $record) => redirect("/matters/$record->id")),
];
}
}
class ListMatters extends ListRecords
{
protected static string $resource = MatterResource::class;

protected function getActions(): array
{
return [
Actions\CreateAction::make()
->disableCreateAnother()
->afterFormFilled(function() {
$this->dispatchBrowserEvent('focus-matter-title-input');
})
->after(fn (Model $record) => redirect("/matters/$record->id")),
];
}
}
public static function form(Form $form): Form
{
return $form
->schema([
TextInput::make('title')->required()->maxLength(255)
->extraAlpineAttributes([
'x-ref' => 'matter-title-input',
'@focus-matter-title-input.window' => '$nextTick(() => { $refs.matter-title-input.focus(); } )',
]),
Hidden::make('owner_id')->default(auth()->id()),
]);
}
public static function form(Form $form): Form
{
return $form
->schema([
TextInput::make('title')->required()->maxLength(255)
->extraAlpineAttributes([
'x-ref' => 'matter-title-input',
'@focus-matter-title-input.window' => '$nextTick(() => { $refs.matter-title-input.focus(); } )',
]),
Hidden::make('owner_id')->default(auth()->id()),
]);
}
Want results from more Discord servers?
Add your server
More Posts
Make the component use the w-full spaceHey friends, is there a way in which the components occupy the maximum width available between the sIssues with Registering Panels in FilamentPHP: Seeking Help and InsightsHello everyone, I'm currently working on a package that adds modular functionality to Filament and How to change the title of tab elements in related resource ?Hello! Could you help me? I have a resource form and the table of the related resource at the bottoUpdate value of the repeater component using $setHey guys, it's possible update value of the repeater component, using $set? And after update the valCustomizing the Unique validation ruleHow would I appropriately customize the Unique validation rule/method that Filament has according toHeader in a Card Form builderIs it possible to add a header to a card tag by enclosing a code segment? ```php Card::make() ->scBypass automatic case alterations for labelsHi. I can't figure out how to bypass the case alterations that are happening for resource names. Fodisable lazy loading when testingIs there a way to disable lazy loading relation managers and widgets in testing environment? I wantHow to use tailwind css inside the filament custom created page?I have configured tailwind css with laravel. Inside my welcome.blade.php tailwind classes working fiHow to prevent tags in TagInput from doubling when reordering items in RepeaterI have a TagInput inside a Repeater that gets auto populated based on existing data. Every time I re