F
Filament5mo ago
morty

Sorry this might be dumb, but how can I extend a method that returns a component with additional...

This might be a PHP question more than a Filament question but I'll ask anyway. I'm trying to extend the default login of Filament to add a tab index attribute to the remember me input. This is what I tried:
protected function getRememberFormComponent(): Component
{
$component = parent::getRememberFormComponent();

return $component->extraInputAttributes(['tabindex' => 3]);
}
protected function getRememberFormComponent(): Component
{
$component = parent::getRememberFormComponent();

return $component->extraInputAttributes(['tabindex' => 3]);
}
Unfortunately this doesn't work, there is no extraInputAttributes method on the component returned from the parent method. I could just copy the method to override it and add my change but I wanted to avoid any issues with future updates to this method from Filament.
Solution:
It should recognize it. Maybe it just needs to reindex.
Jump to solution
7 Replies
Igor
Igor5mo ago
Can you confirm the component import ? should be Filament\Forms\Components\Component;
morty
morty5mo ago
confirmed
<?php

namespace App\Filament\Pages;

use Filament\Actions\Action;
use Filament\Facades\Filament;
use Filament\Forms\Components\Component;
use Filament\Forms\Components\TextInput;
use Filament\Pages\Auth\Login as BaseLogin;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\HtmlString;

class Login extends BaseLogin
{
...
<?php

namespace App\Filament\Pages;

use Filament\Actions\Action;
use Filament\Facades\Filament;
use Filament\Forms\Components\Component;
use Filament\Forms\Components\TextInput;
use Filament\Pages\Auth\Login as BaseLogin;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\HtmlString;

class Login extends BaseLogin
{
...
morty
morty5mo ago
No description
awcodes
awcodes5mo ago
What does dd($component) show?
morty
morty5mo ago
Filament\Forms\Components\Checkbox#1
(
[*:evaluationIdentifier] => 'component'
[*:view] => 'filament-forms::components.checkbox'
[*:defaultView] => null
[*:viewData] => [],
[*:viewIdentifier] => 'field'
[*:model] => null
[*:loadStateFromRelationshipsUsing] => null
[*:saveRelationshipsUsing] => null
[*:saveRelationshipsBeforeChildrenUsing] => null
[*:shouldSaveRelationshipsWhenHidden] => false
[*:cachedConcealingComponent] => null
[*:isDisabled] => false
[*:isHidden] => false
[*:isVisible] => true
[*:cachedParentRepeater] => null
[*:columnSpan] => [
'default' => 1,
'sm' => null,
'md' => null,
'lg' => null,
'xl' => null,
'2xl' => null,
]
[*:columnStart] => [
'default' => null,
'sm' => null,
'md' => null,
'lg' => null,
'xl' => null,
'2xl' => null,
]
Filament\Forms\Components\Checkbox#1
(
[*:evaluationIdentifier] => 'component'
[*:view] => 'filament-forms::components.checkbox'
[*:defaultView] => null
[*:viewData] => [],
[*:viewIdentifier] => 'field'
[*:model] => null
[*:loadStateFromRelationshipsUsing] => null
[*:saveRelationshipsUsing] => null
[*:saveRelationshipsBeforeChildrenUsing] => null
[*:shouldSaveRelationshipsWhenHidden] => false
[*:cachedConcealingComponent] => null
[*:isDisabled] => false
[*:isHidden] => false
[*:isVisible] => true
[*:cachedParentRepeater] => null
[*:columnSpan] => [
'default' => 1,
'sm' => null,
'md' => null,
'lg' => null,
'xl' => null,
'2xl' => null,
]
[*:columnStart] => [
'default' => null,
'sm' => null,
'md' => null,
'lg' => null,
'xl' => null,
'2xl' => null,
]
[*:cachedActions] => null
[*:actions] => [],
[*:actionFormModel] => null
[*:childComponents] => [],
[*:fieldWrapperView] => null
[*:id] => null
[*:hasInlineLabel] => null
[*:key] => null
[*:isLabelHidden] => false
[*:label] => 'Remember me'
[*:shouldTranslateLabel] => false
[*:maxWidth] => null
[*:meta] => [],
[*:afterStateHydrated] => Closure#2
(
[0] => Closure#2(...)
)
[*:afterStateUpdated] => [],
[*:beforeStateDehydrated] => null
[*:defaultState] => false
[*:dehydrateStateUsing] => null
[*:mutateDehydratedStateUsing] => null
[*:mutateStateForValidationUsing] => null
[*:hasDefaultState] => true
[*:isDehydrated] => true
[*:statePath] => 'remember'
[*:stripCharacters] => null
[*:listeners] => [],
[*:columns] => null
[*:extraAttributes] => [],
[*:stateBindingModifiers] => null
[*:liveDebounce] => null
[*:isLive] => null
[*:isLiveOnBlur] => false
[*:isAutofocused] => false
[*:isMarkedAsRequired] => true
[*:isRequired] => false
[*:regexPattern] => null
[*:rules] => [
0 => [
0 => 'boolean',
1 => true,
],
]
[*:validationMessages] => [],
[*:validationAttribute] => null
[*:helperText] => null
[*:hint] => null
[*:cachedHintActions] => null
[*:hintActions] => [],
[*:hintColor] => null
[*:hintIcon] => null
[*:hintIconTooltip] => null
[*:name] => 'remember'
[*:isInline] => true
[*:extraInputAttributes] => [],
)
[*:cachedActions] => null
[*:actions] => [],
[*:actionFormModel] => null
[*:childComponents] => [],
[*:fieldWrapperView] => null
[*:id] => null
[*:hasInlineLabel] => null
[*:key] => null
[*:isLabelHidden] => false
[*:label] => 'Remember me'
[*:shouldTranslateLabel] => false
[*:maxWidth] => null
[*:meta] => [],
[*:afterStateHydrated] => Closure#2
(
[0] => Closure#2(...)
)
[*:afterStateUpdated] => [],
[*:beforeStateDehydrated] => null
[*:defaultState] => false
[*:dehydrateStateUsing] => null
[*:mutateDehydratedStateUsing] => null
[*:mutateStateForValidationUsing] => null
[*:hasDefaultState] => true
[*:isDehydrated] => true
[*:statePath] => 'remember'
[*:stripCharacters] => null
[*:listeners] => [],
[*:columns] => null
[*:extraAttributes] => [],
[*:stateBindingModifiers] => null
[*:liveDebounce] => null
[*:isLive] => null
[*:isLiveOnBlur] => false
[*:isAutofocused] => false
[*:isMarkedAsRequired] => true
[*:isRequired] => false
[*:regexPattern] => null
[*:rules] => [
0 => [
0 => 'boolean',
1 => true,
],
]
[*:validationMessages] => [],
[*:validationAttribute] => null
[*:helperText] => null
[*:hint] => null
[*:cachedHintActions] => null
[*:hintActions] => [],
[*:hintColor] => null
[*:hintIcon] => null
[*:hintIconTooltip] => null
[*:name] => 'remember'
[*:isInline] => true
[*:extraInputAttributes] => [],
)
Looks like I may have spoke too soon when I said "doesn't work". It does in fact work with the way I did it. It looks like it's just Phpstorm complaining for no reason. With that being said, do you know how to make Phpstorm not recognize it as a method not found? 🤣
Solution
awcodes
awcodes5mo ago
It should recognize it. Maybe it just needs to reindex.
Want results from more Discord servers?
Add your server
More Posts