F
Filament6mo ago
xb23

Help with a Form and ViewField::make

I cant figure this out, so in a form I'm using a ViewField to make a visual element of the data in the form, but if I have a select box called 'owners' how can I pass the value of 'owners' into the ViewField?
3 Replies
LeandroFerreira
LeandroFerreira6mo ago
via $set. The ViewField has an state:
Forms\Components\Select::make('select')
->options([
'1' => 'Option1',
'2' => 'Option2',
])
->live()
->afterStateUpdated(function (Forms\Set $set, ?string $state) {
$set('viewField', $state);
}),
Forms\Components\ViewField::make('viewField')
->view('view-field')
Forms\Components\Select::make('select')
->options([
'1' => 'Option1',
'2' => 'Option2',
])
->live()
->afterStateUpdated(function (Forms\Set $set, ?string $state) {
$set('viewField', $state);
}),
Forms\Components\ViewField::make('viewField')
->view('view-field')
<!-- view-field.blade.php -->
<div>
{{ $getState() }}
</div>
<!-- view-field.blade.php -->
<div>
{{ $getState() }}
</div>
xb23
xb23OP6mo ago
Fab, is there way I can send the entire form state, so all the current filled out fields? And then if I wanted to send values from the ViewField into the main form is that possible?
LeandroFerreira
LeandroFerreira6mo ago
I think you can get all fields using $this->data Yes, you get the state from the viewField when you submit the form
Want results from more Discord servers?
Add your server