FilamentF
Filament2y ago
Ashk

Accessing a form component from another

Hello,
I would like to know if it is possible to access another component from a component. For example, I'd like to modify the placeholder of a TextInput according to a record field selected in a Select.

I tried something like this, I can access the other component, but getSelectedRecord is still null, as if the state didn't change
[
    Forms\Components\Select::make('object_id'),
    Forms\Components\TextInput::make('title')
        ->placeholder(fn(HasForms $livewire) => $livewire
            ->getForm('form')
            ?->getComponent('object_id')
            ->getSelectedRecord()
            ?->getAttribute('something')
]


I've got this working, but I'd like if possible to avoid redoing an SQL request for nothing.

[
    Forms\Components\Select::make('object_id'),
    Forms\Components\TextInput::make('title')
        ->placeholder(fn(Forms\Get $get) => Object::find($get('object_id'))->something)
]


TY !
Was this page helpful?