Having viewData with value of another field available

Hi,

I'm trying to get the value of a hidden field within another field (which is just a view). Here is my code;

return $form
->schema([
Forms\Components\Hidden::make('test')
->default('hello),
Forms\Components\ViewField::make('another')
->view('forms.components.another')
->viewData(['test' => function(callable $get) { $get('test'); }, ]),
]);

I hoped that $get would be called and give me the value of the field available in my view, but when I do this in my view;

@php
dump($test)
@endphp

I get:

Closure(callable $get) {#2840 // resources/views/forms/components/another.blade.php
class: "App\Filament\Resources\ProjectResource"
}

And not the value "hello"?
Solution
not sure what you are trying to do, but ViewField has a state and you can use this

Forms\Components\ViewField::make('another')
    ->formatStateUsing(fn (Forms\Get $get): string => $get('test'))


<!-- forms.components.another -->
<div>
    {{ $getState() }}
</div>
Was this page helpful?