F
Filament3mo ago
nowak

Searchable select field shows incorrect search results

I added a select field to my form like this:
Select::make('product_id')
->label('Product')
->relationship('productSku.product', 'name', function (Builder $query, Get $get) {
$mealTypeId = $get('../../meal_type_id');
$query->byMealType($mealTypeId)->orderBy('id');
})
->afterStateUpdated(fn (Select $component) => $component
->getContainer()
->getComponent('dynamicSkuFields')
->getChildComponentContainer()
->fill())
->afterStateHydrated(function (Set $set, Get $get, $record) {
if ($record) {
$productSku = ProductSku::find($get('product_sku_id'));
if ($productSku) {
$set('product_id', $productSku->product_id);
}
}
})
->preload()
->required()
->dehydrated(false)
->live()
->columnSpan([
'md' => 5,
])
->searchable()
->hidden(function (Get $get, ?UserOrderItem $record) {
$status_id = $get('../../status_id');
return $record !== null && $status_id !== 1;
}),
Select::make('product_id')
->label('Product')
->relationship('productSku.product', 'name', function (Builder $query, Get $get) {
$mealTypeId = $get('../../meal_type_id');
$query->byMealType($mealTypeId)->orderBy('id');
})
->afterStateUpdated(fn (Select $component) => $component
->getContainer()
->getComponent('dynamicSkuFields')
->getChildComponentContainer()
->fill())
->afterStateHydrated(function (Set $set, Get $get, $record) {
if ($record) {
$productSku = ProductSku::find($get('product_sku_id'));
if ($productSku) {
$set('product_id', $productSku->product_id);
}
}
})
->preload()
->required()
->dehydrated(false)
->live()
->columnSpan([
'md' => 5,
])
->searchable()
->hidden(function (Get $get, ?UserOrderItem $record) {
$status_id = $get('../../status_id');
return $record !== null && $status_id !== 1;
}),
When I then search for a string, results are shown for records that do not contain the string added to the input field, which is not what I would expect to happen. Is this happening due to the complexitty of my Select field? Or is this standard searchable select field behaviour?
0 Replies
No replies yetBe the first to reply to this messageJoin