Skip to content

WeSelect

A powerful select/autocomplete component that extends Vuetify's v-autocomplete with built-in API data fetching, pagination, object handling, and other advanced features.

Usage

vue
<template>
  <!-- Basic usage -->
  <WeSelect
    v-model="selectedValue"
    label="Service"
    resource="services"
  />
  
  <!-- With object value binding -->
  <WeSelect
    v-model="selectedId"
    v-model:object-value="selectedObject"
    label="User"
    resource="users"
    item-text="full_name"
    return-object
  />
  
  <!-- With pagination -->
  <WeSelect
    v-model="selectedUser"
    label="User"
    resource="users"
    item-text="full_name"
    paginate
  />
  
  <!-- Multiple selection -->
  <WeSelect
    v-model="selectedServices"
    multiple
    label="Services"
    resource="services"
  />
</template>

Props

PropTypeDefaultDescription
resourceStringundefinedAPI resource path to fetch items from
modelValueString | Object | Array | Boolean | Numberundefinedv-model value
objectValueString | Object | Array | Boolean | NumbernullContains the ID value(s) when using v-model:object-value, not the full object
returnObjectBooleanfalseWhether to return the full object instead of just the ID
extraParamsObject{}Additional parameters for the API request
itemValueString'id'Property name to use as the value
itemTextString | Function'name'Property name or function to use as display text
clearableBooleantrueWhether the field can be cleared
paginateBoolean | ObjectfalseWhether to use pagination and pagination options
multipleBooleanfalseWhether to allow multiple selections
searchAsItemBooleanfalseWhether to include search text as an item
lazyBooleanfalseWhether to use lazy loading/caching for API requests
autoSelectString | FunctionundefinedAuto selection mode: 'first', 'only-option', or custom function

Note: The component also accepts all Vuetify v-autocomplete props through v-bind="$attrs"

Events

EventPayloadDescription
update:modelValueanyEmitted when the model value changes
update:object-valueanyEmitted when the object value changes (when using v-model:object-value)
errorErrorEmitted when an error occurs during API request

Slots

NamePropsDescription
item{ item, props, index }Custom template for each item
search-item{ value }Custom template for the search item when searchAsItem is true

Features

  • API Integration: Automatically fetches data from specified API resource
  • Dual Model Binding: Supports both value and object value binding
  • Infinite Scrolling: Built-in pagination with infinite scroll loading
  • Auto Selection: Can automatically select first item or based on custom logic
  • Server-Side Search: Search functionality when using pagination
  • Lazy Loading: Optional request caching for improved performance

Examples

Basic Usage

vue
<script setup>
const selectedService = ref(null)
</script>

<template>
  <WeSelect
    v-model="selectedService"
    label="Select a service"
    resource="services"
  />
</template>

Return Object vs Value Only

vue
<script setup>
const returnObject = ref({
  value: null,      // Will contain the full object when returnObject is true
  objectValue: null // Will contain just the ID value
})
</script>

<template>
  <WeSelect
    v-model="returnObject.value"
    v-model:object-value="returnObject.objectValue"
    label="Service with object value"
    resource="services"
    return-object
  />
</template>

Paginated Selection

vue
<script setup>
const paginatedUser = ref(null)
</script>

<template>
  <WeSelect
    v-model="paginatedUser"
    label="Find a user (with pagination)"
    resource="users"
    item-text="full_name"
    paginate
  />
</template>

Multiple Selection

vue
<script setup>
const multipleServices = ref([])
</script>

<template>
  <WeSelect
    v-model="multipleServices"
    multiple
    label="Select multiple services"
    resource="services"
  />
</template>

Lazy Loading

vue
<script setup>
const lazySelection = ref(null)
</script>

<template>
  <WeSelect
    v-model="lazySelection"
    label="Cached selection"
    resource="beacons"
    :paginate="false"
    lazy
  />
</template>

Auto Selection

vue
<script setup>
// Auto-select first item
const autoSelectFirst = ref(null)

// Auto-select with custom function
const autoSelectCustom = ref([])
</script>

<template>
  <!-- Automatically select first item -->
  <WeSelect
    v-model="autoSelectFirst"
    label="Auto-select first"
    resource="services"
    auto-select="first"
  />
  
  <!-- Automatically select items using a custom function -->
  <WeSelect
    v-model="autoSelectCustom"
    label="Auto-select custom"
    resource="services"
    chips
    multiple
    :auto-select="(item, index) => index < 3"
  />
</template>

Source Code