FleetbaseFleetbase

Select

<Select> is the standard HTML-native single-value dropdown. Accepts an options array or hash, supports custom labels, value paths, humanization, and yielded option rendering.

<Select>

<Select> is the standard single-value dropdown. It wraps a native <select> element with Fleetbase's form styling, plus convenience for option labels, value paths, and humanization.

For an autocomplete / typeahead, use <ComboBox>. For selecting a Fleetbase model record, use <ModelSelect>.

Basic Usage

<Select
  @value={{this.driver.status}}
  @options={{this.statusOptions}}
  @placeholder="Select a status"
  @onSelect={{fn (mut this.driver.status)}}
/>
statusOptions = ['active', 'inactive', 'pending'];

Object Options

When options are objects, point at the label and value properties via @optionLabel and @optionValue:

<Select
  @value={{this.driver.zone_id}}
  @options={{this.zones}}
  @optionLabel="name"
  @optionValue="id"
  @placeholder="Select a zone"
  @onSelect={{fn (mut this.driver.zone_id)}}
/>
zones = [
  { id: 'zn_a', name: 'North' },
  { id: 'zn_b', name: 'South' },
];

Humanizing Raw Values

If your options are slugs/snake-case, set @humanize={{true}} to display them human-readable (pickup_readyPickup Ready):

<Select
  @value={{this.order.status}}
  @options={{array "created" "dispatched" "pickup_ready" "completed"}}
  @humanize={{true}}
  @onSelect={{fn (mut this.order.status)}}
/>

Yielding Custom Option Markup

If you need rich option content, yield a block. The yielded value is the label (or option), and the second positional yield is the option itself or the hash key:

<Select @value={{this.choice}} @options={{this.colors}} @optionLabel="name" @onSelect={{fn (mut this.choice)}} as |label color|>
  <span style={{html-safe (concat "color:" color.hex)}}>{{label}}</span>
</Select>

Hash Options

When @options is a plain object (key/value hash), pass @fetched={{true}} to enable hash iteration:

<Select
  @options={{this.optionsHash}}
  @fetched={{true}}
  @optionLabel="label"
  @onSelect={{fn (mut this.value)}}
/>

Arguments

ArgumentTypeDefaultDescription
@valueanyThe current selection
@optionsarray | objectThe options to display. Array of primitives or objects, or a hash when @fetched={{true}}
@optionLabelstringPath on each option object for the display label
@optionValuestringPath on each option object for the value (otherwise the object itself)
@optionClassstringClass on each <option>
@placeholderOptionClassstringClass on the placeholder <option>
@placeholderstringPlaceholder rendered as a disabled selected option
@humanizebooleanfalseHumanize option labels via safe-humanize
@fetchedbooleanfalseHash-iteration mode for @options as {key: object}
@disabledbooleanfalseDisable the select
@unstyledbooleanfalseDrop the form-select styling
@defaultStylingDisabledbooleanfalseLike @unstyled but doesn't drop the has--selection / disabled modifiers
@onSelect(value) => voidCalled with the new value on change
@onChange(event, value) => voidCalled with the raw change event in addition to @onSelect

Any additional ...attributes are forwarded to the <select> element.

Distinguishing @onSelect vs @onChange

Both fire on every change:

  • @onSelect(value) — gets just the value
  • @onChange(event, value) — gets the raw DOM event plus value

Use whichever fits your handler signature.

Real-World Examples

{{!-- Status dropdown --}}
<Select
  @value={{this.order.status}}
  @options={{array "created" "preparing" "ready" "dispatched" "completed"}}
  @humanize={{true}}
  @placeholder="Status"
  @onSelect={{fn (mut this.order.status)}}
/>

{{!-- Object options with custom label/value --}}
<Select
  @value={{this.gateway.driver}}
  @options={{this.availableGateways}}
  @optionLabel="name"
  @optionValue="code"
  @placeholder="Choose a gateway"
  @onSelect={{this.onGatewayChange}}
/>

{{!-- Inside an InputGroup --}}
<InputGroup @name="Default Currency">
  <Select
    @value={{this.settings.currency}}
    @options={{this.currencies}}
    @optionLabel="name"
    @optionValue="code"
    @onSelect={{fn (mut this.settings.currency)}}
  />
</InputGroup>

See Also

Source

Select | Fleetbase