Skip to content

Instantly share code, notes, and snippets.

@dantrevino
Last active December 16, 2019 05:31
Show Gist options
  • Save dantrevino/06519731c592133305386839984cb25b to your computer and use it in GitHub Desktop.
Save dantrevino/06519731c592133305386839984cb25b to your computer and use it in GitHub Desktop.
<q-select
borderless
v-model="model"
clearable
use-chips
use-input
fill-input
input-debounce="0"
:options="options"
@filter="filterFn"
:behavior="$q.platform.is.ios === true ? 'dialog' : 'menu'"
hint="ex: user.id or user.id.blockstack"
placeholder="Search Blockstack names"
>
<template v-slot:before>
<q-icon name="search" />
</template>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey">
No results
</q-item-section>
</q-item>
</template>
<template v-slot:selected-item="scope">
<q-item>
<q-item-section avatar>
<q-avatar>
<img :src="scope.opt.icon" />
</q-avatar>
</q-item-section>
<q-item-section>
<q-item-label>{{ scope.opt.label }}</q-item-label>
<q-item-label caption>{{ scope.opt.id }}</q-item-label>
</q-item-section>
</q-item>
</template>
<template v-slot:option="scope">
<q-item v-bind="scope.itemProps" v-on="scope.itemEvents">
<q-item-section avatar>
<q-avatar size="lg">
<img :src="scope.opt.icon" />
</q-avatar>
</q-item-section>
<q-item-section>
<q-item-label v-html="scope.opt.label"></q-item-label>
</q-item-section>
</q-item>
</template>
</q-select>
@dantrevino
Copy link
Author

dantrevino commented Dec 16, 2019

Screenshot from 2019-12-15 17-37-04

@dantrevino
Copy link
Author

options: [ { label: String, id: String, icon: String(url) } ]

@Cmacu
Copy link

Cmacu commented Dec 16, 2019

hide-selected: Hides selection; Use the underlying input tag to hold the label (instead of showing it to the right of the input) of the selected option; Only works for non 'multiple' Selects

@dantrevino
Copy link
Author

dantrevino commented Dec 16, 2019

hide-selected: Hides selection; Use the underlying input tag to hold the label (instead of showing it to the right of the input) of the selected option; Only works for non 'multiple' Selects

Ok so maybe I'm just confused by what I'm seeing. I want this:

Screenshot from 2019-12-15 17-37-04b

How do I replace the input? Is there a slot? or a reference to the input slot? ... From the examples I can only see a select slot.

@dantrevino
Copy link
Author

dantrevino commented Dec 16, 2019

This worked:

  <q-select
        v-model="model"
        clearable
        :use-input="showInput"
        hide-selection
        fill-input
        input-debounce="0"
        :options="options"
        @filter="filterFn"
        :behavior="$q.platform.is.ios === true ? 'dialog' : 'menu'"
        hint="ex: user.id or user.id.blockstack"
        placeholder="Search Blockstack names"
        @input="selectUser"
      >
        <template v-slot:before>
          <q-icon name="search" />
        </template>
        <template v-slot:no-option>
          <q-item>
            <q-item-section class="text-grey">
              No results
            </q-item-section>
          </q-item>
        </template>
        <template v-slot:selected-item="scope">
          <q-item v-bind="scope.itemProps">
            <q-item-section avatar>
              <q-avatar>
                <img :src="scope.opt.icon" />
              </q-avatar>
            </q-item-section>
            <q-item-section>
              <q-item-label>{{ scope.opt.label }}</q-item-label>
              <q-item-label caption>{{ scope.opt.id }}</q-item-label>
            </q-item-section>
          </q-item>
        </template>
        <template v-slot:option="scope">
          <q-item v-bind="scope.itemProps" v-on="scope.itemEvents">
            <q-item-section avatar>
              <q-avatar size="lg">
                <img :src="scope.opt.icon" />
              </q-avatar>
            </q-item-section>
            <q-item-section>
              <q-item-label v-html="scope.opt.label"></q-item-label>
            </q-item-section>
          </q-item>
        </template>
      </q-select>

Thanks @Cmacu!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment