Live select field not found with $get
In a create form, I have a select field called base_position_id defined as
Right below that, I have this inside a Split and a Section:
which works perfectly. So I know base_position_id is getting set correctly and should be available.
But a little farther down I have another select field that I'd like to filter based on base_position_id.
Obviously on first load, the logged value is empty. But when I select a base_position_id and the field refreshes, it still logs a blank value. Shouldn't I be getting the selected value at that point? I need it to add a filter to the return collection.
Solution:Jump to solution
sorry, i miss-read where the relationship was. try
$get('../base_position_id')
since you are in a layout component you need to traverse out of it to get the state from other fields.11 Replies
Also, if I dd($get) at the point of the log line, I have a Get object with only one component, the current select field itself.
Hi, I'm no expert in filament, but maybe this could help:
Instead of:
->options(function (Get $get) {
Can you try:
->options(function (callable $get) {
I appreciate the suggestion. Sadly, no joy. Same result. Or rather same lack of result.
Options() and relationship() don’t work together. It should be one or the other. The third parameter of relationship() can be used to modify the query to “filter” results. https://filamentphp.com/docs/3.x/forms/fields/select#customizing-the-relationship-query
Maybe what I'm trying to do isn't possible then. The way I understand it is that relationship() on the Select is used to populate the options and then save that relation to the primary model and relationship() on the layout components is for saving fields to relationships.
In my case, the relationship on the Grid is there to have a place to (optionally) save the value if one is selected - an override of the default value currently assigned - but the select list options are coming from an entirely different model. I'm pulling those options in just fine. What I'm trying to do is to filter out the selected code as well as the currently assigned manager from the list since the override value can't be either of those.
Solution
sorry, i miss-read where the relationship was. try
$get('../base_position_id')
since you are in a layout component you need to traverse out of it to get the state from other fields.Ah, so Get is scoped to the layout component? Good to know.
yea, same with Set
trying to find the docs about it.
might be better to think of it as scoped to the level of the component in the data array, if that makes sense.
but it can be traversed similar to traversing a directory structure
Okay, cool. Thanks. I didn't think that was an issue since I was able to access it inside a Split >> Section >> Placeholder structure. Anyway, It's something to try next time I run up against it.
And that worked great, btw
You’re split and section probably aren’t using relationships so the data wouldn’t be nested. Cheers.
That makes sense, thanks