$get() in Wizard Form is null
Hi all !
I have the same problem as this topic : https://discord.com/channels/883083792112300104/1159576155746213918/1159576155746213918
In my case, I've a Select form in the first step where the user choose a building (or can create new one) :
On step 2, I have another select in a repeater where I want to use the ID of the building field (step 1) to make a query search. So, I use Get $get for that :
The $get return null. If I do a $get of another field on the current step, it's work.
Is there anything special I need to do to retrieve the field value in a repeater and form wizard?
Thanks in advance π
10 Replies
Ok, I found that : https://filamentphp.com/docs/3.x/forms/fields/repeater#using-get-to-access-parent-field-values
So, I try to use this :
dd($get('../building'));
(with one "../", two and three) but same result.
Is there a way to DD the form structure?I found another way, but I don't know if it's a good one π
So... I'd like your opinion. I use the Livewire component to retrieve the field value and perform the search. The result is as follows: And⦠It's work. Seem ok?
So... I'd like your opinion. I use the Livewire component to retrieve the field value and perform the search. The result is as follows: And⦠It's work. Seem ok?
You'd have to traverse back, you can see how far you need to traverse by running dd($get). Something like you said with ../../ likely needed more ../../../../building
You can dom that but I would have done:
data_get('building', $livewire->data, '')
Thanks for your feedback.
The docs specify that
$get
is scoped in the repeater when used inside.
When I do a dd($get)
, I only get the select input in the second step, but not all fields.
$livewire->data
return an array with all fields and their values.
If I do data_get('building', $livewire->data, '');
I've got an empty string in return.
Same with data_get('building', $livewire->data['building'], '');
and data_get('../building', $livewire->data['building'], '');
I guess using $building_id = $livewire->data['building'];
is valid?Yours is valid if building exists always!! You can also do:
data_get('building', $livewire->data['building']);
That's all right then, because you can't go on to step 2 if the "building" field is empty π
However, the
data_get
returns null
and I'm having a bit of trouble understanding why... Knowing that $livewire->data['building']
does return a result.
I guess it's having trouble finding the 'building' field but I've tried with '../' and '../../' and it doesn't make any difference. However, as expressed in my first message, I just have 2 steps with a repeater in the second.
I'm tempted to say that it's not too bad as long as $livewire->data is ok, but uh π€·ββοΈdata_get returns null when there is no default valu. What does building return? It would be an empty string surely which was what we were previously providing?
Yeah you are right though π
$livewire->data['building']
return the ID of the option selected in the select building field (on step 1).
For example, 168.Solution
because I made a typo!
data_get($livewire->data, 'building')
Aaaaahh okay, it happens even to the best.
All is good now.
Thanks, I will use it, didn't know that helper! π