Choose a record by any part of its name
RecordSelect searches the related table while you type: upper or lower case, any part of the name, and the start of each word. Results are ranked, with exact matches and matches at the start first.
Note: Try it
Open the field and type bay groc: Bayside Grocers. Then type pasta: North End Pasta Co. Choose it and press “Show what would be saved”: the key of the customer.
Initials
Typing the first letter of each word finds a record, as people say “NEPC” for North End Pasta Co. It is on by default and used for 2 to 6 letters; ->searchInitials(false) turns it off.
Note: Try it
Type nepc in “Customer”: North End Pasta Co. Type nepc in “Customer, without initials” (->searchInitials(false)): nothing matches.
A code next to the name
->codeAttribute('sku') shows the item number before the name, in the list and in the field, and searches it too. Numbers that start with what you typed come first.
Note: Try it
Type a-12: A-120 Machine screw, A-122, A-124, A-126 and A-128 Hex nut. Then type hex nut: A-128 is found by its name.
Japanese names by their reading
->searchReading('name_kana') searches the reading (furigana) column. Hiragana, katakana, half-width katakana and romaji all find the name.
Note: Try it
Type やまだ, then ヤマダ, then ヤマダ, then yamada: each finds 山田商事. Type hokuto: 北斗物産.
Recently used first
With ->rememberRecent(), opening the empty field lists the records this person chose recently and often, under “Recently used”. A record is remembered when the form is saved, not while choosing.
Note: Try it
Choose Seaport Events and press “Show what would be saved” (as saving does). Clear the field with the × and open it again: Seaport Events is at the top under “Recently used”.
Add what you typed, in one click
With ->createOptionInline(), a search with no record of exactly that name ends with “Add …”. Clicking it (or pressing Enter on it) creates the record and chooses it, without a modal. Without other settings, the name column is set to what you typed.
Note: Try it
Type Acme Corp and click “Add “Acme Corp””. The new customer is created and chosen. (The demo data is put back every hour.)
Choose what a new record gets
->createOptionUsing(fn (string $name) => [...]) decides the columns of the new record. Here a new customer also gets the next customer number.
Note: Try it
Type Lowell Lumber and click “Add “Lowell Lumber””. The field reads C-1025 Lowell Lumber (or a higher number if other people added customers): the new customer got the next number.
Who may add records
->canCreateOption() decides who may add. By default, it is the create ability of the model’s policy (everyone when there is no policy). It is checked on the server for every add. Here it is false.
Note: Try it
Type Acme Inc: nothing matches, and there is no “Add …” at the end.
How many results are shown
A search shows up to 20 results. Here ->optionsLimit(3) shows 3.
Note: Try it
Type co: only 3 customers are shown, although 7 names contain “co”.
Listing records before typing
Without typing, the field lists only recently used records. ->preload() also lists the first records by name when the field is opened empty.
Note: Try it
Open the field without typing: products are listed right away, sorted by name.
A table of columns in the list
->columns([...]) lists the records as a table with a heading over each column, so similar names can be told apart by code, price or pack size. Prices use the same format as MoneyColumn. The field still saves only the key.
Note: Try it
Type wrench: three wrenches are listed with their code, price and pack size. Choose one: the field shows its name. Press “Show what would be saved”: the product’s id, its key in the products table.
Using it with the keyboard
↑ and ↓ move, Enter chooses, Esc closes the list, and Tab goes to the next field. Screen readers hear the list and the number of results.
Note: Try it
Click the field, type salem, press ↓ and Enter: Salem Candle Works is chosen. Press Esc to close the list without choosing.
Choose many from two lists
For choosing many items out of a long list, such as the regions a carrier delivers to. The left list shows what you can still choose, the right list what you chose. Double-click an item, press the arrow buttons or drag it to move it, and search either list. PickList saves the same as Select with multiple(): an array of keys.
Note: Try it
Double-click New England. Click Midwest, hold Ctrl (⌘ on a Mac) and click Pacific, then press the › button: both move to the right. Drag Canada onto the right list. Press “Show what would be saved”: ["ne","mw","pa","ca"].
Put the chosen items in order
With ->reorderable(), the chosen items can be put in order, and the order is saved: the first key is the first choice. Each item shows its number.
Note: Try it
Move UPS, FedEx and USPS to the right. Click USPS and press the ˄ button twice: it becomes number 1. You can also drag it, or press Alt+↑ and Alt+↓ in the right list. Press “Show what would be saved”: ["usps","ups","fedex"].
Limit how many can be chosen
With ->maxItems(3), no more than 3 items can be moved to the right. The number above the right list shows how many are chosen out of how many are allowed, and a note says when items were left out.
Note: Try it
Press the » button to move every region: only the first 3 move, the right list shows “3 of 3”, and the note below it says the rest were not added.
Many records, searched on the server
When the items come from a table with many records (here, the customers), the browser doesn’t get them all: the left list shows the first few by name, and typing searches on the server by name, code or initials, like RecordSelect. The choice is saved to a many-to-many relationship, so there is no “Show what would be saved” here: the right list is what would be saved.
Note: Try it
The left list says it shows the first 8. Type harbor in its search: Harborview Hotel is found on the server. Double-click it: it moves to the right with its customer number.
Suggestions from your data
SuggestInput is a text field that suggests values while you type, but anything else can be typed too. ->suggestFrom(Customer::class, 'city') suggests the cities already in the customers table, the most used first, without repeats.
Note: Try it
Type bo: Boston is suggested. Then type Boston Harbor instead, which isn’t in the list, and press “Show what would be saved”: "Boston Harbor", exactly as typed.
Suggestions from part of your data
The third argument of ->suggestFrom() filters the rows. Here only customers in the United States are used.
Note: Try it
Type to: Boston is suggested, but not Toronto, because that customer is in Canada. Type port: Portland.
A fixed list of suggestions
->suggestions([...]) suggests the values of a list.
Note: Try it
Type fed: FedEx Express and FedEx Ground. Click one.
Suggestions from your own search
->suggestions(fn (string $search) => ...) runs your own search with what was typed and suggests what it returns. Here it searches the product names.
Note: Try it
Type wrench: the wrenches of the product list are suggested.
Your recent values first
With ->rememberRecent(), what this person saved recently and often comes first, marked “Recently used”. Up to 50 values are kept per person and field, and a value used long ago slowly drops down. With Filament tenancy, each tenant has its own lists.
Note: Try it
Type Lowell and press “Show what would be saved” (as saving does). Clear the field and type lo: Lowell is at the top, marked “Recently used”.
How many suggestions are shown
Up to 8 suggestions are shown. Here ->suggestionsLimit(3) shows 3.
Note: Try it
Click the empty field: only 3 cities are suggested.
Using it with the keyboard
↓ and ↑ move through the suggestions, Enter takes one, and Esc closes the list. When no suggestion is highlighted, Enter submits the form as usual.
Note: Try it
Type ups, press ↓ twice and Enter: UPS Next Day Air is filled in.