#Live select field not found with $get

17 messages · Page 1 of 1 (latest)

fallen palm
#

In a create form, I have a select field called base_position_id defined as

 Select::make('base_position_id')
   ->label('Position')
   ->placeholder('Select a Base Position from DGP')
   ->options(function () {
       return BasePosition::all()->sortBy('jobTitle')->pluck('jobTitle', 'id')
           ->filter(fn($value, $key) => Position::where('base_position_id', $key)
               ->get()
               ->isEmpty());
   })
   ->required()
   ->live(),

Right below that, I have this inside a Split and a Section:

 Placeholder::make('code')
     ->label('Position Code:')
     ->inlineLabel()
     ->content(fn(Get $get) => $get('base_position_id') ?: '')
     ->disabled(),

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.

Grid::make()
   ->relationship('alt_manager_code')
   ->columns(1)
   ->schema([
      Select::make('managerCode')
          ->label('Override Hiring Manager')
          ->placeholder('Select Position to Override Manager')
          ->options(function (Get $get) {
              info($get('base_position_id'));  // LOG TO SEE IF VALUE IS AVAILABLE
              return BasePosition::all()
                  ->sortBy('jobTitle')
                  ->pluck('jobTitle', '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.

lucid fjordBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

fallen palm
#

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.

sterile nebula
#

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) {

fallen palm
modern mantle
fallen palm
# modern mantle Options() and relationship() don’t work together. It should be one or the other....

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.

modern mantle
fallen palm
modern mantle
#

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

fallen palm
#

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

lucid fjordBOT
modern mantle