Select::createOptionUsing not updating selected element in v3

I can't make it work. I'm using v3.0.39
Here is an dummy example
Select::make('test')
->options(function(){
return Tag::pluck('name','id');
})
->createOptionForm([TextInput::make('name')])
->createOptionUsing(function($data){
$tag = new Tag();
$tag->fill($data);
$tag->save();
return $tag->getKey();
})
Select::make('test')
->options(function(){
return Tag::pluck('name','id');
})
->createOptionForm([TextInput::make('name')])
->createOptionUsing(function($data){
$tag = new Tag();
$tag->fill($data);
$tag->save();
return $tag->getKey();
})
The record is created but the select doesn't reflect the change. Thanks in advance
26 Replies
toeknee
toeknee15mo ago
Q.. Why not use:
->relationship(name: 'author', titleAttribute: 'name')
->createOptionAction(
fn (Action $action) => $action->modalWidth('3xl'),
)
->relationship(name: 'author', titleAttribute: 'name')
->createOptionAction(
fn (Action $action) => $action->modalWidth('3xl'),
)
as per the docs?
Fabien K.
Fabien K.OP15mo ago
Because it's not a real eloquent relationship in the model.
toeknee
toeknee15mo ago
So make it a relationship? since tag is a table on its own?
Fabien K.
Fabien K.OP15mo ago
Thanks for the suggestion but it's not possible. My implementation (which I cannot share) is more complicated than the example. I simplified it to demonstrate the issue. ( It was working in v2 btw). So we're not supposed to use createOptionUsing anymore ?
toeknee
toeknee15mo ago
Ah ok
Fabien K.
Fabien K.OP15mo ago
Sorry I fixed the example, the class wass wrong I tried with a real relationhship and I have the same result. Select is not filled after creating an item
LeandroFerreira
LeandroFerreira15mo ago
return $tag ?
Fabien K.
Fabien K.OP15mo ago
Select::make('tagsCategory')
->relationship('tagsCategory','name')
->createOptionForm([
TextInput::make('name'),
Hidden::make('group')->default('product_category'),
])->label('real relationship')
Select::make('tagsCategory')
->relationship('tagsCategory','name')
->createOptionForm([
TextInput::make('name'),
Hidden::make('group')->default('product_category'),
])->label('real relationship')
Here is the code I used for the real relationship test (like in the doc)
LeandroFerreira
LeandroFerreira15mo ago
Is it creating the record?
Fabien K.
Fabien K.OP15mo ago
It's creating the record. The issue is just the select field not updating with the created record
LeandroFerreira
LeandroFerreira15mo ago
Select::make('tag_category_id') ? What is the column name?
Fabien K.
Fabien K.OP15mo ago
It's a morphToMany relationship so no column name
LeandroFerreira
LeandroFerreira15mo ago
->multiple() ?
Fabien K.
Fabien K.OP15mo ago
oh yes that can explain why it's not working on the real relationship example not a good example then 😄 Ok so i did another test with a single relationship
LeandroFerreira
LeandroFerreira15mo ago
real relationship? What does it mean? If you are using morph, you should use morphto relationships.. ? https://filamentphp.com/docs/3.x/forms/fields/select#handling-morphto-relationships
Fabien K.
Fabien K.OP15mo ago
Another simpler test
php

public function tag(){
return $this->belongsTo(Tag::class);
}
php

public function tag(){
return $this->belongsTo(Tag::class);
}
php
Select::make('tag_id')->relationship('tag','name')
->createOptionForm([
TextInput::make('name'),
Hidden::make('group')->default('product_category'),
])->label('real single relationship'),
php
Select::make('tag_id')->relationship('tag','name')
->createOptionForm([
TextInput::make('name'),
Hidden::make('group')->default('product_category'),
])->label('real single relationship'),
It seems to be a frontend issue, The select field does not reflect the change but the state seems to be ok after creating.
Fabien K.
Fabien K.OP15mo ago
LeandroFerreira
LeandroFerreira15mo ago
why is it working here? https://demo.filamentphp.com/shop/orders/1/edit try to add a customer
Fabien K.
Fabien K.OP15mo ago
that's my question. why it's not working 😄 Yeah it works fine
LeandroFerreira
LeandroFerreira15mo ago
maybe you can clone https://github.com/filamentphp/demo and compare to your project.. similar
Forms\Components\Select::make('shop_customer_id')
->relationship('customer', 'name')
->searchable()
->required()
->createOptionForm([
Forms\Components\TextInput::make('name')
->required(),
...
Forms\Components\Select::make('shop_customer_id')
->relationship('customer', 'name')
->searchable()
->required()
->createOptionForm([
Forms\Components\TextInput::make('name')
->required(),
...
did you try to remove hidden field, as a test?
GitHub
GitHub - filamentphp/demo: Source code for the demo.filamentphp.com...
Source code for the demo.filamentphp.com website. Contribute to filamentphp/demo development by creating an account on GitHub.
Fabien K.
Fabien K.OP15mo ago
cleared cache, forced asset update, no more idea yes I made my first tests without the hidden field I'll try the demo well I'm out of ideas. Same version of filament and livewire on the demo and my test project and still not working on my test project. removed all vendors. reinstalled. cleared all caches. republished assets. no luck. When I add ->searchable() it's working.
LeandroFerreira
LeandroFerreira15mo ago
weird, can you share the project on github?
Fabien K.
Fabien K.OP15mo ago
hhm not really. But I did try to remove searchable on the filament demo (customer field in the order resource) (don't forget to delete some customers first) and it's not working either. So it seems to be a bug when not searchable
LeandroFerreira
LeandroFerreira15mo ago
hum You can open an issue on GitHub, but honestly, I don't think it's a significant problem because you can use "searchable + preload.
Fabien K.
Fabien K.OP15mo ago
yeah, i'll just put seachable+ preload. Thanks for your time
Ben
Ben15mo ago
oh wow, i have the exact same problem and the same solution. @fabien.karsegard do you work with multi tenancy? With searchable and preload it works. Thanks for this 😄 ...
Want results from more Discord servers?
Add your server