FilamentF
Filament14mo ago
Garrita

Get state from form to createOptionForm

I want to get the person_type state from the form to the createOptionForm modal, I've tried $get('../person_type') or '../../' but it does not work.
Radio::make('person_type')
                    ->label(__('Person Type'))
                    ->options(PersonType::class)
                    ->default(PersonType::Natural)
                    ->formatStateUsing(fn (?Dealer $record) => $record?->person_type ?? PersonType::Natural)
                    ->live(),

                Select::make('user_id')
                    ->label(__('User'))
                    ->relationship(
                        name: 'user',
                        titleAttribute: 'name',
                        modifyQueryUsing: fn ($query) => $query->whereDoesntHave('dealer'),
                        ignoreRecord: true
                    )
                    ->getOptionLabelFromRecordUsing(fn (User $user) => $user->name.' - '.($user->email ?? $user->phone))
                    ->native(false)
                    ->searchable()
                    ->preload()
                    ->createOptionForm([
                        TextInput::make('name')
                            ->label(function (Get $get) {
                                return $get('../person_type') === PersonType::Natural ? __('Name') : __('Company Name');
                            })
                            ->required(),
]);
Was this page helpful?