Skip to content

prvious/combobox

Repository files navigation

Filament Combobox

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Description bla bla bla ...

Installation

You can install the package via composer:

composer require prvious/filament-combobox

Optionally, you can publish the views using

php artisan vendor:publish --tag="filament-combobox-views"

This is the contents of the published config file:

return [
];

Usage

Basic Usage

use Prvious\Filament\Combobox\Components\Combobox;

Combobox::make('status')
    ->options([
        'draft' => 'Draft',
        'published' => 'Published',
        'archived' => 'Archived',
    ])

Setting a Search Query

You can set a search query that will be displayed in the search input when the component loads:

Combobox::make('product')
    ->searchable()
    ->options([
        // your options
    ])
    ->searchQuery('electronics')

This will populate the search input with "electronics" but will not trigger a search automatically.

Auto-Triggering a Search on Load

If you want to perform a search automatically when the component boots, use the autoSearch() method along with searchQuery():

Combobox::make('product')
    ->searchable()
    ->getSearchResultsUsing(function (string $search) {
        return Product::where('name', 'like', "%{$search}%")
            ->limit(50)
            ->pluck('name', 'id')
            ->toArray();
    })
    ->searchQuery('electronics')
    ->autoSearch()

This is useful when you want to pre-filter options based on context, such as:

  • Showing products from a specific category
  • Filtering items based on user permissions
  • Displaying search results based on a related field value

You can also conditionally enable auto-search:

Combobox::make('product')
    ->searchable()
    ->searchQuery($categoryName)
    ->autoSearch(filled($categoryName))

Note: The autoSearch() method requires that the component is searchable and has a search handler configured.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

No description, website, or topics provided.

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •