$get utility in infolist

I have an infolist which consists of a Tabs component with Tabs, as would be expected. In one of these Tabs, I would like to put a non-dehydrated Select and some Action buttons, and the function for the Action's action() would need to access the value of the Select. I've tried to inject the $get utility in the Closure, but it's returning null, even with $get('*'). After some debugging, I know that the $get's $component property inside the Action's Closure is actually the parent Tab, since clearly the Action itself isn't a Component, doesn't use the HasState trait and doesn't have access to the makeGetUtility() method. I have excluded the Select being dehydrated(false) as the cause, since elsewhere in my Panel I've been able to $get() a Select's value even though it was dehydrated(false) (unless that behaves differently in infolists? It's all Schemas in v4 afaik...). My suspicion is that the Tab maybe behaves differently than the average Component when $get is invoked? I'm not sure how to go about retrieveing the Select's value inside the Action's action().
1 Reply
Mombei
MombeiOP3w ago
I dug deeper in the Get class source code and the related methods called in its __invoke() and I was eventually able to get my value by doing two things: 1) set a custom statepath on the Select, like ->statePath('data.option') 2) get that custom statepath, like $get('data.option') The reason this works is that at the end of the day, when the Tab is used as the $component for the Get, it's not able to resolve the path with its call to ->getRootContainer()->getComponentByStatePath(), so it falls back to data_get($livewire, $path). By setting a custom statepath for the value I want to retrieve, I can place that value in the livewire component's $data array, so that the fallback will give me the value I'm trying to get. I would like a cleaner solution though

Did you find this page helpful?