F
Filamentβ€’8mo ago
zander9255

Select box key-value pair

Hi guys! I have a selectbox component in my form. I would like to do some processing on the form once this field has been selected. I am currently tying into the afterStateUpdated function, and I do get the selectbox selection "ID" but I would like to also get the Label being displayed. Currently the $state variable only returns the "ID" Is there an easier way of getting this label, without doing another database search? Unfortunately, I can't search a declared variable of options here, since this changes depending on another input higher up in the form. $origpersField = Forms\Components\Select::make('ORIGPERS') ->label('From') ->columnSpan($defColSpan) ->live() ->afterStateUpdated(function ($state, Forms\Set $set, Forms\Get $get) { echo 'after Updated'; var_dump($state); // returns key var_dump($get('ORIGPERS')); // returns key
Solution:
Try this, don't know if this is the best answer but solves your problem πŸ˜‰ ``` ->afterStateUpdated(function($state, Forms\Components\Select $component){ dd($component->getoptions()[$state]); })...
Jump to solution
4 Replies
Solution
Tally
Tallyβ€’8mo ago
Try this, don't know if this is the best answer but solves your problem πŸ˜‰
->afterStateUpdated(function($state, Forms\Components\Select $component){
dd($component->getoptions()[$state]);
})
->afterStateUpdated(function($state, Forms\Components\Select $component){
dd($component->getoptions()[$state]);
})
zander9255
zander9255OPβ€’8mo ago
Thank you so much Tally! Will give it a bash Brilliant, worked like a charm!
LeandroFerreira
LeandroFerreiraβ€’8mo ago
->afterStateUpdated(function (?string $state, Select $component) {
dump("key: {$state}, value: {$component->getOptionLabel()}");
})
->afterStateUpdated(function (?string $state, Select $component) {
dump("key: {$state}, value: {$component->getOptionLabel()}");
})
Tally
Tallyβ€’8mo ago
oew this is nice as well πŸ˜‰
Want results from more Discord servers?
Add your server