Error when I use searchable() in wizard step

Hello everyone. I have an error when I want to use a Select with searchable() in a wizard step. Error: Cannot read properties of null (reading 'location'), my code: Wizard\Step::make('form') ->icon('heroicon-o-pencil') ->label('Formulario') ->schema([ Forms\Components\TextInput::make('name') ->label('Nombre') ->required(), Forms\Components\TextInput::make('last_name') ->label('Apellidos') ->required(), Forms\Components\TextInput::make('dni') ->label('DNI') ->required(), Forms\Components\Select::make('location') ->label('Población') ->required() ->options(CpMunicipality::get()->take(20)->pluck('name', 'id')) ->searchable() ->columnSpan(3), Forms\Components\TextInput::make('contact_name') ->label('Nombre persona contacto') ->required(), Forms\Components\TextInput::make('contact_last_name') ->label('Apellido persona contacto') ->required(), Forms\Components\TextInput::make('email') ->label('Email') ->required(), Forms\Components\TextInput::make('phone') ->label('Teléfono') ->required(), ]), If I remove searchable(), the error goes away. Can anybody help me? I am doing something wrong? Thank you
10 Replies
toeknee
toeknee2y ago
try:
>options(fn() => CpMunicipality::get()->take(20)->pluck('name', 'id'))
>options(fn() => CpMunicipality::get()->take(20)->pluck('name', 'id'))
That wojn't work either you need morelike: and
->getSearchResultsUsing(fn (string $search) => CpMunicipality::where('name', 'like', "%{$search}%")->limit(50)->pluck('name', 'id'))
->getSearchResultsUsing(fn (string $search) => CpMunicipality::where('name', 'like', "%{$search}%")->limit(50)->pluck('name', 'id'))
astronomic
astronomicOP2y ago
Thank you but I keep getting the error. My code: Forms\Components\Select::make('location') ->label('Población') ->required() ->options(fn() => CpMunicipality::get()->take(20)->pluck('name', 'id')) ->getSearchResultsUsing(fn (string $search) => CpMunicipality::where('name', 'like', "%{$search}%")->limit(50)->pluck('name', 'id')) ->searchable(),
toeknee
toeknee2y ago
->options(fn() => CpMunicipality::limit(20)->pluck('name', 'id'))
->options(fn() => CpMunicipality::limit(20)->pluck('name', 'id'))
How about that? Failing that I am unsure
astronomic
astronomicOP2y ago
No, stay the same 😭
LeandroFerreira
I don't believe that searchable() is the issue Can you share the whole code please?
astronomic
astronomicOP2y ago
Hi, I'm sorry for the delay. This is my whole code. I have cleaned up the code and I have left only a select without a wizard at the end, and the same error appears. I think it's because it's a Livewire component, it's the first time I've used it. Maybe i'm missing something ?
toeknee
toeknee2y ago
You have missed the mount functio off
public function mount() {
$this->form->fill([]);
}
public function mount() {
$this->form->fill([]);
}
astronomic
astronomicOP2y ago
Omgsh, thank you very much, now it works! The only thing, I don't have to fill in is the form, can I leave the fill empty?
toeknee
toeknee2y ago
Yep, that's what [] does. If you wanted values you put them in there.
astronomic
astronomicOP2y ago
Ok, thank you @toeknee_iom muito obrigada @leandro_ferreira
Want results from more Discord servers?
Add your server