F
Filament14mo ago
Antoine

Access any field from form with anonymous action

Hello everybody, I have an anonymous function right in the middle of a form, I want to access my "quantity" field from the action() method of my anonymous function.
TextInput::make('quantity')
->label(__('fields.quantity'))
->numeric()
->step(0.1),

Actions::make([
Action::make('test')
->action(function(Get $get, Set $set, Livewire $livewire) {

// Need to get the value of the step of Quantity field
// Something like this : $livewire->component('quantity')->getStep();
// But doesnt work

// Some code...

}),
])
TextInput::make('quantity')
->label(__('fields.quantity'))
->numeric()
->step(0.1),

Actions::make([
Action::make('test')
->action(function(Get $get, Set $set, Livewire $livewire) {

// Need to get the value of the step of Quantity field
// Something like this : $livewire->component('quantity')->getStep();
// But doesnt work

// Some code...

}),
])
How to do ? I didn't find much choice in the documentation or on the internet... Thank's
Solution:
```php ->action(function (\Filament\Forms\Components\Component $component) { $container = $component->getContainer()->getParentComponent()->getContainer(); $quantity = $container->getComponent('data.quantity'); //$quantity->getStep()...
Jump to solution
5 Replies
LeandroFerreira
LeandroFerreira14mo ago
$get('quantity') ?
Antoine
AntoineOP14mo ago
This method only retrieves the value of my field. And this is the only interaction we can have with anonymous form functions. I am looking to be able to modify the appearance or retrieve information from my field. For example, I'm looking to access my field so I can make it disabled once I click my anonymous action button. I know that there is this kind of method but I cannot access my component as it is not linked to my action. It's impossible for me to do anything.
->afterStateUpdated(fn (Select $component) => $component
->getContainer()
->getComponent('dynamicTypeFields')
->getName())
->afterStateUpdated(fn (Select $component) => $component
->getContainer()
->getComponent('dynamicTypeFields')
->getName())
https://filamentphp.com/docs/3.x/forms/advanced#dynamic-fields-based-on-a-select-option
Solution
LeandroFerreira
LeandroFerreira14mo ago
->action(function (\Filament\Forms\Components\Component $component) {
$container = $component->getContainer()->getParentComponent()->getContainer();
$quantity = $container->getComponent('data.quantity');
//$quantity->getStep()
})
->action(function (\Filament\Forms\Components\Component $component) {
$container = $component->getContainer()->getParentComponent()->getContainer();
$quantity = $container->getComponent('data.quantity');
//$quantity->getStep()
})
Antoine
AntoineOP13mo ago
Thank you Leandro, I was just looking for that!

Did you find this page helpful?