Last Nested Select component doesn't work with ->multiple() function attached to it

When trying to chain the dependent select, the last select doesn't work with multiple() attached to it, any guidance in the right direction would be highly appreciated! protected function getFormSchema(): array { return [ Grid::make(2) ->schema([ Forms\Components\Select::make('section_id') ->label('Sections') ->options(Section::where('is_active',true) ->orderBy('name','asc') ->pluck('name','id') ) ->required() ->reactive() ->callAfterStateUpdated(fn (callable $set) => $set($this->certification_id, null)), Forms\Components\Select::make('certification_id') ->label('Certification') ->options(Certification::where('is_active',true) ->where('section_id',$this->section_id) ->orderBy('name','asc') ->pluck('name','id') ) ->preload() ->required() ->reactive() ->callAfterStateUpdated(fn (callable $set) => $set($this->domains, null)), Forms\Components\Select::make('domains') ->options(Domain::where('is_active',true) ->where('certification_id',$this->certification_id) ->orderBy('name','asc') ->pluck('name','id') ) // ->multiple() ->preload() ->required(), ]; } If I remove ->multiple() from the last select, it works and the values and listed down in the dropdown. Thanks in advance !
5 Replies
LeandroFerreira
I didn't understand your code, but if it is working, the issue can be the type of the value that you are trying to set... it should be an array, like $set('domains', [1, 2, 3])
awcodes
awcodes2y ago
Should also be ->afterStateUpdated()
aliaxon
aliaxonOP2y ago
@Leandro Ferreira I'm trying to create a reactive select filed form with section being the parent,. Section->Certification->Domain i.e: from section drop down select, when a user select section A it will only list child records in Certificaiton select fiel and vise versa for domain select field. The code works as intended with ->multiple() commented-out, which effectively passes domain_id to livewire variable, but if I try to make the variable as an array and set the selection option to ->multiple(), nothing is listed for selection on domain. If I run the query on database, it returns 8 domains which should be listed in this select menu.
Kenneth Sese
Kenneth Sese2y ago
@aliaxon Try the below. I tested a similar setup with my app with three levels of select and a multiple select at the end and everything works as it should. Hopefully this will help.
Forms\Components\Select::make('section_id')
->label('Sections')
->options(fn () => Section::where('is_active', true)
->orderBy('name','asc')
->pluck('name','id')
)
->required()
->reactive()
->afterStateUpdated(fn (callable $set) => $set('certification_id', null)),

Forms\Components\Select::make('certification_id')
->label('Certification')
->options(fn (callable $get) => Certification::where('is_active', true)
->where('section_id', $get('section_id'))
->orderBy('name','asc')
->pluck('name','id')
)
->required()
->reactive()
->afterStateUpdated(fn (callable $set) => $set('domains', null)),

Forms\Components\Select::make('domains')
->options(fn (callable $get) => Domain::where('is_active', true)
->where('certification_id', $get('certification_id'))
->orderBy('name','asc')
->pluck('name','id')
)
->multiple()
->required(),
Forms\Components\Select::make('section_id')
->label('Sections')
->options(fn () => Section::where('is_active', true)
->orderBy('name','asc')
->pluck('name','id')
)
->required()
->reactive()
->afterStateUpdated(fn (callable $set) => $set('certification_id', null)),

Forms\Components\Select::make('certification_id')
->label('Certification')
->options(fn (callable $get) => Certification::where('is_active', true)
->where('section_id', $get('section_id'))
->orderBy('name','asc')
->pluck('name','id')
)
->required()
->reactive()
->afterStateUpdated(fn (callable $set) => $set('domains', null)),

Forms\Components\Select::make('domains')
->options(fn (callable $get) => Domain::where('is_active', true)
->where('certification_id', $get('certification_id'))
->orderBy('name','asc')
->pluck('name','id')
)
->multiple()
->required(),
As was stated above it's afterStateUpdate(). Also you should be using closures to get the parent state.
aliaxon
aliaxonOP2y ago
@kennethsese Much appreciated, working as expected! (y)
Want results from more Discord servers?
Add your server