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:Jump to 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'))...5 Replies
Solution
not sure what you are trying to do, but
ViewField
has a state and you can use this
That helped me out, thanks!
Nice, but how to pass the value of $get('test') to the ViewField blade file?
I'm talking about dynamic value from another (dependant) field. Looking for that approach