create account

One Of Those Clever Drop Down Boxes That Fills Things In For You by brianoflondon

View this thread on: hive.blogpeakd.comecency.com
· @brianoflondon · (edited)
$21.80
One Of Those Clever Drop Down Boxes That Fills Things In For You
---
***[Building the next v4v.app v2](https://peakd.com/created/v4vapp-v2)***

***This is a value for value post: see the explanation in the footer.***

---

## A simple tool for selecting Hive accounts from a drop down in Vue 3, Quasar Framework using the Composition API.

This is going to sound stupid to those of you who haven't ever tried to program or learned a new programming skill after years but it's not joke to say that it has taken me a year to properly understand this.

It really shouldn't have been so hard for me to figure it out, but it was. I have something like this working on [v4v.app](https://v4v.app/) right now but I honestly don't know how I managed to get it working.

For now you can see this selector (and a fancier one) working on this demo page: https://demo.v4v.app/selectdemo

![image.png](https://files.peakd.com/file/peakd-hive/brianoflondon/23t75BUgLfiWPLwL8ovaSBmZ1YhP7Mr9qXK4Ev1YxJWDqt97xgbj8DBhPowM9SVJFw7zu.png)

Only now have I actually built this thing in such a way that I understand every line of code.

## The HiveSelectAcc component

I've actually built a simple one and a more complex one but I'm presenting the simple one first because I hope this is easier to understand.

If any of you Javascript wizards can tell me I'm doing this wrong, I'd love to hear from you. In the meantime, this is what I came up with.

## Select object for Hive Accounts

This is the extended explanation for the Simple selector for picking Hive Accounts: `HiveSelectAcc`.

This selector uses the Quasar `q-select` object and uses autocompletion based on the partial Hive account name entered. It looks up and presents options from the Hive API sorted in descending order of Hive account reputation. If an exact match for the entered Hive account is found, that is returned.

This Component emits the selected Hive account name and displays the selected Hive account's profile picture.

https://github.com/brianoflondon/v4vapp-frontend-v2/blob/f99a30a3cb208da0770497c1cabdf5ab27655690/src/components/SelectHiveAcc.vue

### Template

The Template options as set are taken from this example in the Quasar Documentation [SelectAfterFiltering](https://quasar.dev/vue-components/select#example--selecting-option-after-filtering).

Unfortunately all the examples in the Quasar documentation use the older Options API and I'm working with the newer Compositions API. I converted this example and you can find the converted version [at this link](https://github.com/brianoflondon/v4vapp-frontend-v2/blob/f99a30a3cb208da0770497c1cabdf5ab27655690/src/components/quasar/SelectAfterFiltering.vue)


```vue
<template>
  <q-select
    class="hive-select-account"
    v-model="model"
    hide-selected
    use-input
    fill-input
    options-html
    input-debounce="300"
    spellcheck="false"
    :label="label"
    :options="options"
    @filter="filterFnAutoselect"
    @filter-abort="abortFilterFn"
    @keydown.enter="enterFn"
    @keydown.tab="enterFn"
    @keydown.esc="escFn"
    @input-value="inputFn"
  >
    <template v-slot:before>
      <q-avatar rounded size="md">
        <img :src="avatar" @error="handleImageError" />
      </q-avatar>
    </template>
    <template v-slot:no-option>
      <q-item>
        <q-item-section class="text-grey"> No results </q-item-section>
      </q-item>
    </template>
  </q-select>
</template>

```

### Script Setup

You will noticed that this component uses calls from `src/use/useHive.js` which I will also include below.

The optional props are described in the comment section.




```vue
<script setup>
/**
 * SelectHiveAcc
 * A select component for picking Hive accounts
 *
 * @props {string} label - The prompt label to show in the Select box
 * @props {number} maxOptions - Default: 10 - Maximum number of options to show in the dropdown
 * @props {string} size - Default: small - small, medium, large size of the avatar
 * @emits {string} updateValue - Emitted value of selected Hive Account
 */
import { ref, watch } from "vue"
import {
  useLoadHiveAccountsReputation,
  useBlankProfileURL,
  useHiveAvatarURL,
} from "src/use/useHive"

const options = ref([])
const model = ref()
const avatar = ref(useBlankProfileURL())
const emit = defineEmits(["updateValue"])
const props = defineProps({
  label: {
    type: String,
    default: "Hive Account",
  },
  maxOptions: {
    type: Number,
    default: 10,
  },
  size: {
    type: String,
    default: "small",
  },
  fancyOptions: {
    type: Boolean,
    default: false,
  },
})

watch(model, (newValue) => {
  // Watches the model which holds the selected value
  avatar.value = useHiveAvatarURL({ hiveAccname: newValue, size: props.size })
  emit("updateValue", newValue)
})

function enterFn(input) {
  // If Enter or tab is pressed before selecting from the options, the first option is selected
  if (!model.value && options.value.length > 0) {
    model.value = options.value[0]
  }
  emit("updateValue", model.value)
}

function escFn(input) {
  // If Esc is pressed, the model is cleared
  model.value = ""
}

function inputFn(input) {
  // Change the avatar to match the input value
  setHiveAvatar(input)
}

function setHiveAvatar(hiveAccname) {
  avatar.value = useHiveAvatarURL({ hiveAccname, size: props.size })
}

function handleImageError(event) {
  avatar.value = useBlankProfileURL()
}

async function filterFnAutoselect(val, update, abort) {
  // Finds relevant Hive accounts for the options drop down
  update(
    async () => {
      if (val === "") {
        options.value = []
      } else {
        // Fetch the sorted list of Hive accounts after converting
        // the input to lowercase and removing spaces
        const needle = val.toLowerCase().replace(/\s+/g, "")
        options.value = await useLoadHiveAccountsReputation(
          needle,
          props.maxOptions
        )
        // Sets the displayed Hive avatar to the first option in the
        // options list
        if (options.value) {
          setHiveAvatar(options.value[0])
        }
      }
    },
    (ref) => {
      if (val !== "" && ref.options.length > 0 && ref.getOptionIndex() === -1) {
        ref.moveOptionSelection(1, true)
        ref.toggleOption(ref.options[ref.optionIndex], true)
      }
    }
  )
  abort(() => {
    abortFilterFn
  })
}

const abortFilterFn = () => {
  console.log("delayed filter aborted")
}
</script>

<style lang="scss" scoped></style>
```


### Hive Functions

First note is that I'm using the HiveTx library. [Hive-tx-js](https://github.com/mahdiyari/hive-tx-js). I was unable to get this to work successfullyy by installing with `yarn` so I copied the minified js file into my project and I import it like this:

`import "src/assets/hive-tx.min.js"`

You can see the complete file here: [useHive.js](https://github.com/brianoflondon/v4vapp-frontend-v2/blob/b2d442d248e5f3ae0a61c45f4156ef9db8dc9e1b/src/use/useHive.js)


## How to use the Template

This should be all you need to put the object in your own project. Once this object is on the page you will have access to the selected Hive account name in the `hiveAccname` variable.


```vue

<template>
  <HiveSelectAcc
    @updateValue="
      (value) => {
        hiveAccname = value
      }
    "
  />
</template>
import { ref } from "vue"
const hiveAccname = ref("")

<script setup>


</script>
```




-------

## Value for Value

For the last few months while building @v4vapp I was generously supported by the DHF. Going forward I have a much more modest support which covers direct server costs and a little of my time.

If you appreciate the work I do on and around Hive, you can express this directly: upvoting posts on Hive is great. Also consider a direct donation (there's a Tip button on Hive or a Lightning Address) on all my posts.

**[Support Proposal 244 on PeakD](https://peakd.com/me/proposals/244)
[Support Proposal 244 with Hivesigner](https://hivesigner.com/sign/update-proposal-votes?proposal_ids=%5B244%5D&approve=true)
[Support Proposal 244 on Ecency](https://ecency.com/proposals/244)
[Vote for Brianoflondon's Witness KeyChain or HiveSigner](https://vote.hive.uno/@brianoflondon)**

-------

<div class="pull-right">

![Send Lightning to Me!](https://files.peakd.com/file/peakd-hive/brianoflondon/AK3gcbmQA5oP28nnfgu5MiW8JCXw1XA6tYghwFWbSkPW2P6hXto5i7TDRTkPRVa.png)
</div>

- [Get Fountain for Podcasts and 3speak shows](https://fountain.fm/refer/brianoflondon-76b73a585e)
- [Find me on Telegram](https://t.me/brianoflondon)
- [V4VAPP Support on Telegram](https://t.me/v4vapp_support)
- [Vote for Brianoflondon's Witness KeyChain or HiveSigner](https://vote.hive.uno/@brianoflondon)
- [Vote for Brianoflondon's Witness direct with HiveSigner](https://hivesigner.com/sign/account-witness-vote?witness=brianoflondon&approve=1)
- [Find my videos on 3speak](https://3speak.online/user/brianoflondon)
- [Verify my ID and Send me a direct message on Keybase](https://keybase.io/brianoflondon)
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 157 others
properties (23)
authorbrianoflondon
permlinkone-of-those-clever-drop-down-boxes-that-fills-things-in-for-you
categoryhive-110369
json_metadata"{"app":"peakd/2023.5.1","format":"markdown","description":"This shouldn't have been so hard to understand.","tags":["v4vapp-v2","developers","leofinance","proofofbrain","v4vapp","javascript","vue3","quasar"],"users":["filter","filter-abort","keydown.enter","keydown.tab","keydown.esc","input-value","error","props","emits","updateValue"],"image":["https://files.peakd.com/file/peakd-hive/brianoflondon/23t75BUgLfiWPLwL8ovaSBmZ1YhP7Mr9qXK4Ev1YxJWDqt97xgbj8DBhPowM9SVJFw7zu.png","https://files.peakd.com/file/peakd-hive/brianoflondon/AK3gcbmQA5oP28nnfgu5MiW8JCXw1XA6tYghwFWbSkPW2P6hXto5i7TDRTkPRVa.png"]}"
created2023-05-21 14:33:48
last_update2023-05-21 14:40:12
depth0
children12
last_payout2023-05-28 14:33:48
cashout_time1969-12-31 23:59:59
total_payout_value10.918 HBD
curator_payout_value10.881 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length8,939
author_reputation705,291,116,411,941
root_title"One Of Those Clever Drop Down Boxes That Fills Things In For You"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id123,693,216
net_rshares46,716,298,475,948
author_curate_reward""
vote details (221)
@behiver ·
$0.43
Nice control allowing a quick search along with a select option. Such components bring more usability and allow also a bit of discovery through retrieving data as you type. Keep on building and learning!
👍  
properties (23)
authorbehiver
permlinkre-brianoflondon-rv0zz8
categoryhive-110369
json_metadata{"tags":["hive-110369"],"app":"peakd/2023.5.1"}
created2023-05-21 20:37:57
last_update2023-05-21 20:37:57
depth1
children0
last_payout2023-05-28 20:37:57
cashout_time1969-12-31 23:59:59
total_payout_value0.216 HBD
curator_payout_value0.216 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length203
author_reputation384,727,385,596,231
root_title"One Of Those Clever Drop Down Boxes That Fills Things In For You"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id123,706,833
net_rshares923,288,318,999
author_curate_reward""
vote details (1)
@bereal47 ·
$0.44
Your really good at this which is quite encouraging for people to learn. 
👍  
properties (23)
authorbereal47
permlinkre-brianoflondon-2023522t124524320z
categoryhive-110369
json_metadata{"tags":["v4vapp-v2","developers","leofinance","proofofbrain","v4vapp","javascript","vue3","quasar"],"app":"ecency/3.0.31-vision","format":"markdown+html"}
created2023-05-22 11:45:24
last_update2023-05-22 11:45:24
depth1
children0
last_payout2023-05-29 11:45:24
cashout_time1969-12-31 23:59:59
total_payout_value0.222 HBD
curator_payout_value0.221 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length73
author_reputation11,251,459,890,980
root_title"One Of Those Clever Drop Down Boxes That Fills Things In For You"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id123,726,431
net_rshares952,698,416,957
author_curate_reward""
vote details (1)
@biyimi ·
$0.17
That will definitely be an amazing tool this will be after been created fully 
👍  
properties (23)
authorbiyimi
permlinkre-brianoflondon-rv0ua1
categoryhive-110369
json_metadata{"tags":["hive-110369"],"app":"peakd/2023.5.1"}
created2023-05-21 18:34:51
last_update2023-05-21 18:34:51
depth1
children0
last_payout2023-05-28 18:34:51
cashout_time1969-12-31 23:59:59
total_payout_value0.086 HBD
curator_payout_value0.086 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length78
author_reputation109,143,107,258,582
root_title"One Of Those Clever Drop Down Boxes That Fills Things In For You"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id123,702,157
net_rshares370,014,863,839
author_curate_reward""
vote details (1)
@djbravo ·
$0.42
The way we use apps etc. the search option is either not working or slow too much which makes the users feel very bad. The way we see your daily post you tell us something new daily special from which we learn a lot. 
👍  
properties (23)
authordjbravo
permlinkre-brianoflondon-2023523t41258359z
categoryhive-110369
json_metadata{"tags":["v4vapp-v2","developers","leofinance","proofofbrain","v4vapp","javascript","vue3","quasar"],"app":"ecency/3.0.31-vision","format":"markdown+html"}
created2023-05-22 23:13:00
last_update2023-05-22 23:13:00
depth1
children0
last_payout2023-05-29 23:13:00
cashout_time1969-12-31 23:59:59
total_payout_value0.210 HBD
curator_payout_value0.209 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length217
author_reputation193,717,735,767,158
root_title"One Of Those Clever Drop Down Boxes That Fills Things In For You"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id123,742,657
net_rshares887,853,374,284
author_curate_reward""
vote details (1)
@hivebuzz ·
Congratulations @brianoflondon! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

<table><tr><td><img src="https://images.hive.blog/60x70/http://hivebuzz.me/@brianoflondon/comments.png?202305211558"></td><td>You made more than 3500 comments.<br>Your next target is to reach 4000 comments.</td></tr>
</table>

<sub>_You can view your badges on [your board](https://hivebuzz.me/@brianoflondon) and compare yourself to others in the [Ranking](https://hivebuzz.me/ranking)_</sub>
<sub>_If you no longer want to receive notifications, reply to this comment with the word_ `STOP`</sub>


To support your work, I also upvoted your post!


**Check out our last posts:**
<table><tr><td><a href="/hive-139531/@hivebuzz/proposal-2324"><img src="https://images.hive.blog/64x128/https://i.imgur.com/RNIZ1N6.png"></a></td><td><a href="/hive-139531/@hivebuzz/proposal-2324">The Hive Gamification Proposal</a></td></tr></table>
properties (22)
authorhivebuzz
permlinknotify-brianoflondon-20230521t161640
categoryhive-110369
json_metadata{"image":["http://hivebuzz.me/notify.t6.png"]}
created2023-05-21 16:16:39
last_update2023-05-21 16:16:39
depth1
children0
last_payout2023-05-28 16:16:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length971
author_reputation368,165,770,014,358
root_title"One Of Those Clever Drop Down Boxes That Fills Things In For You"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id123,697,512
net_rshares0
@iskawrites ·
$0.44
All that matters is that you finally found how this works and you'll be implementing where necessary going forward. Congratulations on the new addition to your coding knowledge. Cheers 🥂
👍  
properties (23)
authoriskawrites
permlinkre-brianoflondon-rv21tu
categoryhive-110369
json_metadata{"tags":["hive-110369"],"app":"peakd/2023.5.1"}
created2023-05-22 10:16:06
last_update2023-05-22 10:16:06
depth1
children0
last_payout2023-05-29 10:16:06
cashout_time1969-12-31 23:59:59
total_payout_value0.222 HBD
curator_payout_value0.222 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length186
author_reputation94,843,249,503,372
root_title"One Of Those Clever Drop Down Boxes That Fills Things In For You"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id123,725,064
net_rshares957,477,219,490
author_curate_reward""
vote details (1)
@itwithsm ·
$0.44
You are doing an amazing job,  I also did some coding and programming, when I was studying, and even built software in c# as my final year project, but now I'm not doing anything like this for the past 5 to 6 years,  It's hard when you have left something and start doing it after a long break.  Just keep doing the good work !!!!
👍  
properties (23)
authoritwithsm
permlinkre-brianoflondon-2023522t12261835z
categoryhive-110369
json_metadata{"tags":["v4vapp-v2","developers","leofinance","proofofbrain","v4vapp","javascript","vue3","quasar"],"app":"ecency/3.0.31-vision","format":"markdown+html"}
created2023-05-22 07:26:21
last_update2023-05-22 07:26:21
depth1
children0
last_payout2023-05-29 07:26:21
cashout_time1969-12-31 23:59:59
total_payout_value0.222 HBD
curator_payout_value0.222 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length330
author_reputation179,333,738,186,452
root_title"One Of Those Clever Drop Down Boxes That Fills Things In For You"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id123,722,669
net_rshares962,271,158,151
author_curate_reward""
vote details (1)
@lee1938 ·
$0.45
https://twitter.com/lee19389/status/1660539392719454210
#hive #posh
👍  
properties (23)
authorlee1938
permlinkrv1sie
categoryhive-110369
json_metadata{"tags":["hive","posh"],"app":"hiveblog/0.1"}
created2023-05-22 06:54:15
last_update2023-05-22 06:54:15
depth1
children0
last_payout2023-05-29 06:54:15
cashout_time1969-12-31 23:59:59
total_payout_value0.226 HBD
curator_payout_value0.226 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length67
author_reputation26,354,609,270,992
root_title"One Of Those Clever Drop Down Boxes That Fills Things In For You"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id123,722,103
net_rshares981,257,466,766
author_curate_reward""
vote details (1)
@lovinggirl ·
$0.45
https://twitter.com/LovingGirlHive/status/1660544874142384128
👍  
properties (23)
authorlovinggirl
permlinkre-brianoflondon-2023522t121530657z
categoryhive-110369
json_metadata{"tags":["v4vapp-v2","developers","leofinance","proofofbrain","v4vapp","javascript","vue3","quasar"],"app":"ecency/3.0.31-vision","format":"markdown+html"}
created2023-05-22 07:15:33
last_update2023-05-22 07:15:33
depth1
children0
last_payout2023-05-29 07:15:33
cashout_time1969-12-31 23:59:59
total_payout_value0.224 HBD
curator_payout_value0.224 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length61
author_reputation25,203,976,142,905
root_title"One Of Those Clever Drop Down Boxes That Fills Things In For You"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id123,722,538
net_rshares971,486,547,747
author_curate_reward""
vote details (1)
@pizzabot ·
<center>PIZZA!
 The Hive.Pizza team manually curated this post.

<sub>Join us in <a href="https://discord.gg/hivepizza">Discord</a>!</sub></center>
properties (22)
authorpizzabot
permlinkre-one-of-those-clever-drop-down-boxes-that-fills-things-in-for-you-20230521t172312z
categoryhive-110369
json_metadata"{"app": "pizzabot"}"
created2023-05-21 17:23:12
last_update2023-05-21 17:23:12
depth1
children0
last_payout2023-05-28 17:23:12
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length147
author_reputation6,167,709,259,287
root_title"One Of Those Clever Drop Down Boxes That Fills Things In For You"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id123,699,885
net_rshares0
@rocksg ·
$0.45
Why this post is not opening in ecency mobile app? Everytime I try to open it says try again. Then I copied the link and opened in my browser.
👍  
properties (23)
authorrocksg
permlinkrv1tlu
categoryhive-110369
json_metadata{"app":"hiveblog/0.1"}
created2023-05-22 07:17:54
last_update2023-05-22 07:17:54
depth1
children0
last_payout2023-05-29 07:17:54
cashout_time1969-12-31 23:59:59
total_payout_value0.222 HBD
curator_payout_value0.223 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length142
author_reputation116,419,036,712,981
root_title"One Of Those Clever Drop Down Boxes That Fills Things In For You"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id123,722,572
net_rshares966,893,871,954
author_curate_reward""
vote details (1)
@the-lead ·
$0.46
Kudos champ you are doing well
👍  
properties (23)
authorthe-lead
permlinkre-brianoflondon-2023521t23375197z
categoryhive-110369
json_metadata{"tags":["v4vapp-v2","developers","leofinance","proofofbrain","v4vapp","javascript","vue3","quasar"],"app":"ecency/3.0.31-vision","format":"markdown+html"}
created2023-05-21 22:37:54
last_update2023-05-21 22:37:54
depth1
children0
last_payout2023-05-28 22:37:54
cashout_time1969-12-31 23:59:59
total_payout_value0.231 HBD
curator_payout_value0.231 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length30
author_reputation71,704,136,690,573
root_title"One Of Those Clever Drop Down Boxes That Fills Things In For You"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id123,711,370
net_rshares986,170,904,157
author_curate_reward""
vote details (1)