F
Filament6mo ago
ehbfa

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
5 Replies
Solution
LeandroFerreira
LeandroFerreira6mo ago
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
ehbfaOP6mo ago
That helped me out, thanks!
gausoft
gausoft3mo ago
Nice, but how to pass the value of $get('test') to the ViewField blade file?
gausoft
gausoft3mo ago
I'm talking about dynamic value from another (dependant) field. Looking for that approach
Want results from more Discord servers?
Add your server