How to set value to createOptionForm from another field?

Hi guys, I need a little help from you. This is part of my contract form. I have two selects: broker and client. For client select I have createOptionForm for modal creation of client. When I set broker_id in first select I want to use it as broker_id in the createOptionForm. I dont know how. Right now, it will probably get value from the same hidden input. It is null on fill, so it gets null.
// ContractResource form()

Forms\Components\Select::make('broker_id') // this is broker_id on contract model
    ->label(__('Broker'))
    ->options(User::pluck('name', 'id'))
    ->default(auth()->id())
    ->dehydrated()
    ->live(),

Forms\Components\Select::make('client_id')
    ->label(__('Client'))
    ->relationship('client')
    ->createOptionForm([
             Forms\Components\Hidden::make('broker_id') // this is broker_id on client model
            ->dehydrateStateUsing(fn (null $state, Forms\Get $get) => $get('broker_id')),

        Forms\Components\Group::make()
            ->schema([
                PhoneInput::make()
                    ->required(),

                EmailInput::make()
                    ->required(),
            ]),
    ])
    ->createOptionModalHeading(__('Create new client')),
Was this page helpful?