Select (Dropdown)
Dropdown field with static options, enums, models and dynamic option sources.
Select fields show a dropdown for picking a single option. Options can be hard-coded or loaded from enums, Eloquent models or custom resolvers.
Basic Usage (Static Options)
Add a select field with static options using the addSelect() builder method:
Available Settings
Dynamic Options
Polyform supports three ways to load options dynamically:
From Enum
Load options from a string-backed PHP enum:
From Model
Load options from a database model (uses id and name by default):
From Custom Resolver
Load options from a class that implements DynamicOptionResolver:
config/polyform.php under the option_sources key. This lets Polyform load and validate options correctly. Searchable Select
Turn on search for long option lists with the searchable() method:
Searchable selects filter options as the user types, making it easy to find items in long lists (countries, timezones, etc.).
Validation
Select fields are validated by the SelectFieldValidator, which checks:
- A value is selected (if the field is required)
- The selected value exists in the available options
- For model-based options, the ID exists in the database
Frontend Behavior
- Dropdown opens on click or keyboard focus
- Arrow keys navigate through options
- Enter key selects the highlighted option
- Escape key closes the dropdown
- Type-to-search when searchable is enabled
- Mobile-optimized native select on small screens
- Shows validation errors inline
Accessibility
Select fields include ARIA attributes, keyboard navigation and screen reader support. The searchable variant announces the number of available options and the current selection.