FleetbaseFleetbase

ModelSelect

<ModelSelect> is a typeahead select for Ember Data records — live-searches the registered store, supports infinite scroll, and accepts the full ember-power-select API.

<ModelSelect>

<ModelSelect> is a typeahead select for Ember Data model records. It live-queries your registered store as the user types and supports infinite scroll. It is the standard way to let a user pick a driver, vehicle, customer, store, or any other Fleetbase resource.

The component wraps ember-power-select and accepts that library's full API on top of its own arguments.

There is also a sibling <ModelSelectMultiple> for multi-value selection — same API but selects an array of records.

Basic Usage

<ModelSelect
  @modelName="vehicle"
  @selectedModel={{this.driver.vehicle}}
  @optionLabel="display_name"
  @placeholder="Select a vehicle"
  @onChange={{fn (mut this.driver.vehicle)}}
/>

The component will issue a store.query('vehicle', { ... }) request, paginated by pageSize (default 25), and update results as the user types.

With Infinite Scroll

Infinite scroll is on by default. Disable it with @infiniteScroll={{false}}:

<ModelSelect
  @modelName="zone"
  @infiniteScroll={{false}}
  @selectedModel={{this.zone}}
  @onChange={{fn (mut this.zone)}}
/>

With Inline Creation

<ModelSelect
  @modelName="tag"
  @selectedModel={{this.tag}}
  @onChange={{fn (mut this.tag)}}
  @withCreate={{true}}
  @onCreate={{this.createTag}}
  @optionLabel="name"
/>

When the user types something not in the list, a "Create…" option appears.

Yielded Block

The yielded value is the option model — useful for rich rendering:

<ModelSelect @modelName="driver" @selectedModel={{this.driver}} @onChange={{fn (mut this.driver)}} as |driver|>
  <Pill @resource={{driver}} @subtitle={{driver.public_id}} />
</ModelSelect>

Arguments

Source

ArgumentTypeDefaultDescription
@modelNamestringEmber Data model name to query
@sourceobjectthe registered store serviceOverride the data source — e.g. for ember-data-has-many-query

Display

ArgumentTypeDescription
@selectedModelmodel | nullThe currently-selected record
@optionLabelstringProperty path on the model used for the label
@searchFieldstringProperty to search on (defaults to @optionLabel)
@placeholderstringPlaceholder for the empty state
@searchPlaceholderstringPlaceholder shown inside the search input
@noMatchesMessagestringMessage shown when no results match
ArgumentTypeDefaultDescription
@infiniteScrollbooleantrueLazy-load results as the user scrolls
@pageSizenumber25Records per page
@debounceDurationnumber250Search debounce in ms
@searchEnabledbooleantrueEnable typeahead search
@perPageParamstringlimitQuery param for the page size
@pageParamstringpageQuery param for the page number

Permissions

ArgumentTypeDescription
@permissionstringIf the user lacks this ability, the select is disabled and shows an "Unauthorized" tooltip

Inline Create

ArgumentTypeDefaultDescription
@withCreatebooleanfalseShow a "Create new…" option when the search has no match
@onCreate(query)Called with the user's typed search when they choose "Create new"

Tooltip

ArgumentTypeDescription
@helpTextstringTooltip text
@exampleTextstringOptional example beneath the tooltip text
@tooltipPlacementstringtop (default), bottom, left, right

Power-Select Pass-Through

In addition to the above, every ember-power-select argument is supported — including @allowClear, @closeOnSelect, @disabled, @multiple, @matcher, @matchTriggerWidth, @onBlur, @onFocus, @onClose, @onOpen, @onKeydown, @onInput, @triggerClass, @dropdownClass, @verticalPosition, @horizontalPosition, @renderInPlace, @triggerComponent, @selectedItemComponent, @searchFieldPosition, etc.

See ember-power-select docs for the full list.

Callbacks

ArgumentSignatureDescription
@onChange(model)Called with the selected model
@onChangeId(id)Called with just the model's id — convenient for binding to a <entity>_uuid field

Real-World Examples

{{!-- Pick a vehicle for a driver --}}
<InputGroup @name="Vehicle">
  <ModelSelect
    @modelName="vehicle"
    @selectedModel={{this.driver.vehicle}}
    @optionLabel="display_name"
    @onChange={{fn (mut this.driver.vehicle)}}
  />
</InputGroup>

{{!-- Pick a customer with rich rendering --}}
<ModelSelect
  @modelName="customer"
  @selectedModel={{this.order.customer}}
  @optionLabel="name"
  @placeholder="Search customers…"
  @onChange={{fn (mut this.order.customer)}}
  as |customer|
>
  <Pill @resource={{customer}} @subtitle={{customer.email}} />
</ModelSelect>

{{!-- Multi-select drivers (uses ModelSelectMultiple) --}}
<ModelSelectMultiple
  @modelName="user"
  @selectedModel={{@network.alertable.for_new_order}}
  @optionLabel="name"
  @onChange={{fn this.makeAlertable "for_new_order"}}
/>

See Also

  • <Select> — for static option lists
  • <ComboBox> — for static option lists with typeahead

Source

ModelSelect | Fleetbase