createOptionForm - item not automatically selected

What I am trying to do: Add new option in select. What I did:
Forms\Components\Select::make('descr_id')
->relationship(name: 'descrizione', titleAttribute: 'descr')
->createOptionForm([
Forms\Components\TextInput::make('descr'),
]),
Forms\Components\Select::make('descr_id')
->relationship(name: 'descrizione', titleAttribute: 'descr')
->createOptionForm([
Forms\Components\TextInput::make('descr'),
]),
//model
public function descrizione()
{
return $this->belongsTo(MalerbaPagamentiDescr::class, 'descr_id','id');
}
//model
public function descrizione()
{
return $this->belongsTo(MalerbaPagamentiDescr::class, 'descr_id','id');
}
My issue/the error: New item is added in the list as expected but not automatically selected.
2 Replies
phphelloworld
phphelloworldOP8mo ago
Can someone point me in the right direction? Thanks in advance
403gtfo
403gtfo4mo ago
Super late but if anyone needs this... My solution for my country field The button still appears but action is blocked.
Select::make('country_id')->relationship('country', 'name')
->rules(['integer', 'exists:countries,id'])->searchable()->preload()
->createOptionForm(
fn(Request $request) => ($request->user()->cannot('create', Country::class)) ? abort(403) : CountryResource::formFields()
),
Select::make('country_id')->relationship('country', 'name')
->rules(['integer', 'exists:countries,id'])->searchable()->preload()
->createOptionForm(
fn(Request $request) => ($request->user()->cannot('create', Country::class)) ? abort(403) : CountryResource::formFields()
),
Want results from more Discord servers?
Add your server