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:Jump to 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]);
})...
4 Replies
Solution
Try this, don't know if this is the best answer but solves your problem π
Thank you so much Tally! Will give it a bash
Brilliant, worked like a charm!
oew this is nice as well π