How can i add select option dynamically from suffixAction ?

I have a select field with one option initially. I have also added a suffixAction to pick a record and trying to add new option from picked record dynamically to select field. but can't do it. can anyone help please?
Forms\Components\Select::make('union_id')
->label(__('labels.union'))
->options(function (): array {
$union = Union::find(auth()->user()->location[0]);
return [
    $union->id => $union->name_bn
];
})
->suffixAction(
Forms\Components\Actions\Action::make("select_union")
    ->icon('heroicon-o-plus')
    ->modalHeading(__('labels.select_union'))
    ->form(self::locationForm())
    ->modalCancelAction(false)
    ->modalSubmitActionLabel(__('labels.select'))
    ->action(function (Set $set, $state, array $data, Component $component) {

    $union = Union::find($data['union']);
    $component->options([
        $union->id => $union->name_bn
    ]);
    $set('union_id', $union->id);
    
    }),
)
Was this page helpful?