You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This works like a charm and there are no issues with that. However in my scenario I have a use case where I would like to dynamically define the list of searchable columns. I first expected this to work out of the box, as searchable() also supports passing a callable that gets evaluated:
Select::make('example_id')
->relationship('example')
->getOptionLabelFromRecordUsing(fn (Model$record) => sprintf('%s (%s)', $record->name, $record->slug))
->searchable(function(): array|false {
// Example of how the callable could still influence search to be disabledif($someLogicHere) { returnfalse; }
// Example of how columns are returned, this would be dynamic (e.g. from some model interface method)// As of today, these are ignored, and it only matters if this callable returns a truthy value to determine searchabilityreturn ['slug', 'name'];
});
The current implementation correctly evaluates this callable during isSearchable(), and proceeds to make the Select field searchable. While this works, the actual searching is broken, never returning any results. This happens because getSearchResultsForJs() will call into getSearchResults(), which calls into the pre-defined getSearchResultsUsing() callable (automatically set when calling relationship()), which then calls getSearchColumns() while building the search query.
Said getSearchColumns() method however will always result in null / an empty list, as it no longer evaluates $this->isSearchable as set by calling searchable(), but instead directly uses $this->searchColumns:
I think it would be neat if getSearchColumns() would also properly evaluate $this->isSearchable() and respect the returned columns. This would also match the behavior that I initially expected.
As of today, there exists no simple method on dynamically defining these columns, without either extending the actual class or redefining the complete logic of getSearchResultsUsing() within the relationship() method.
Note: This actually initially caused an exception to be thrown, as $this->getSearchColumns() returned null when undefined, which broke the foreach loop. I noticed though that the latest version no longer suffers from this thanks to 4331e16, but unfortunately this only fixed the symptom without making dynamic search columns feasible.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
As of today,
Filament\Forms\Components\Select
supports specifying a static list of searchable columns as an array like this:This works like a charm and there are no issues with that. However in my scenario I have a use case where I would like to dynamically define the list of searchable columns. I first expected this to work out of the box, as
searchable()
also supports passing a callable that gets evaluated:The current implementation correctly evaluates this callable during
isSearchable()
, and proceeds to make theSelect
field searchable. While this works, the actual searching is broken, never returning any results. This happens becausegetSearchResultsForJs()
will call intogetSearchResults()
, which calls into the pre-definedgetSearchResultsUsing()
callable (automatically set when callingrelationship()
), which then callsgetSearchColumns()
while building the search query.Said
getSearchColumns()
method however will always result in null / an empty list, as it no longer evaluates$this->isSearchable
as set by callingsearchable()
, but instead directly uses$this->searchColumns
:filament/packages/forms/src/Components/Select.php
Lines 609 to 618 in bf8da41
Unfortunately this does not work, as passing a callable to
searchable()
will skip assigning$this->searchColumns
due to lazy evaluation:filament/packages/forms/src/Components/Select.php
Lines 537 to 548 in bf8da41
I think it would be neat if
getSearchColumns()
would also properly evaluate$this->isSearchable()
and respect the returned columns. This would also match the behavior that I initially expected.As of today, there exists no simple method on dynamically defining these columns, without either extending the actual class or redefining the complete logic of
getSearchResultsUsing()
within therelationship()
method.Note: This actually initially caused an exception to be thrown, as
$this->getSearchColumns()
returned null when undefined, which broke theforeach
loop. I noticed though that the latest version no longer suffers from this thanks to 4331e16, but unfortunately this only fixed the symptom without making dynamic search columns feasible.Beta Was this translation helpful? Give feedback.
All reactions