Using value from parent livewire component in ViewField

I've added a form to a custom livewire component. The form contains a ViewField, and within that view I need to check the value of one of my livewire component's props. I can't just do $complete, that gives an undefined error. If I pass the value in with ->viewData(['complete' => $this->complete]) it works the first time but it's not reactive, when complete changes the view is not updated. Any ideas?
5 Replies
Jack Sleight
Jack SleightOP2w ago
OK this works:
$getLivewire()->complete
$getLivewire()->complete
toeknee
toeknee2w ago
I think You can pass in a closure too:
->viewData(fn($get) => ['complete' => $get('complete')])
->viewData(fn($get) => ['complete' => $get('complete')])
Jack Sleight
Jack SleightOP2w ago
Sadly not:
ViewComponent::viewData(): Argument #1 ($data) must be of type array, Closure given
ViewComponent::viewData(): Argument #1 ($data) must be of type array, Closure given
toeknee
toeknee2w ago
Ok try it on view instead? or on the form I think you can pass the closure in returning the array I\ve done it one second Ok I did it with a section component and did
Section::make('Details')
->columnSpan(3)
->dehydrated(false)
->live()
->schema(fn ($get) => [
ViewField::make('User Details')
Section::make('Details')
->columnSpan(3)
->dehydrated(false)
->live()
->schema(fn ($get) => [
ViewField::make('User Details')
notice the closure in schema
Jack Sleight
Jack SleightOP2w ago
Ah OK, will give that a go, thanks!

Did you find this page helpful?