F
Filament14mo ago
Mikasa

Make Form Component Utility Injection Can be Called from Custom Method

I got custom form field with several custom methods in it, i want to access utility injections ($get, $set, etc.) on my custom methods. i tried
MyCustomForm::make('name')
->myCustomMethod(fn(callable $get) => $get('other_name'))
MyCustomForm::make('name')
->myCustomMethod(fn(callable $get) => $get('other_name'))
but got error that paramater $get is not passed.
Solution:
Also you need to call $this->evaluate() to evaluate your closure. Have a look at the Filament source code to see how it works.
Jump to solution
5 Replies
Hasnayeen
Hasnayeen14mo ago
use Filament\Forms\Get
use Filament\Forms\Get;

MyCustomForm::make('name')
->myCustomMethod(fn(Get $get) => $get('other_name'))
use Filament\Forms\Get;

MyCustomForm::make('name')
->myCustomMethod(fn(Get $get) => $get('other_name'))
Mikasa
MikasaOP14mo ago
still got an error @Hasnayeen
No description
Hasnayeen
Hasnayeen14mo ago
if you're using custom method then you need to use Filament\Support\Concerns\EvaluatesClosures
Solution
Dennis Koch
Dennis Koch14mo ago
Also you need to call $this->evaluate() to evaluate your closure. Have a look at the Filament source code to see how it works.
Mikasa
MikasaOP14mo ago
ahh i see, will try it @Hasnayeen @Dennis Koch , thanks!
Want results from more Discord servers?
Add your server