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 ```php Forms\Components\ViewField::make('another') ->formatStateUsing(fn (Forms\Get $get): string => $get('test'))...
Jump to solution
2 Replies
Solution
LeandroFerreira
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\ViewField::make('another')
->formatStateUsing(fn (Forms\Get $get): string => $get('test'))
<!-- forms.components.another -->
<div>
{{ $getState() }}
</div>
<!-- forms.components.another -->
<div>
{{ $getState() }}
</div>
ehbfa
ehbfa3w ago
That helped me out, thanks!