Autocomplete component for Vue js

Overview

vuejs-auto-complete

Travis Build Version Coveralls github Downloads

A Vue autocomplete component

npm install vuejs-auto-complete --save

Usage

Installation, add autocomplete component into your app

import Vue from 'vue'
import Autocomplete from 'vuejs-auto-complete'

new Vue({
  //...
  components: {
    Autocomplete,
  },
  //...
})

Api data source

<autocomplete
  source="https://api.github.com/search/repositories?q="
  results-property="items"
  results-display="full_name">
</autocomplete>

Object data source

<autocomplete
  :source="[{id:1,name:'abc'},{id:2,name:'def'}]">
</autocomplete>

Full featured example

<autocomplete
  ref="autocomplete"
  placeholder="Search Distribution Groups"
  :source="distributionGroupsEndpoint"
  input-class="form-control"
  results-property="data"
  :results-display="formattedDisplay"
  :request-headers="authHeaders"
  @selected="addDistributionGroup">
</autocomplete>
// parent component
computed: {
  authHeaders () {
    return {
      'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1Ni....'
    }
  },
},
methods: {
  distributionGroupsEndpoint (input) {
    return process.env.API + '/distribution/search?query=' + input
  },
  addDistributionGroup (group) {
    this.group = group
    // access the autocomplete component methods from the parent
    this.$refs.autocomplete.clear()
  },
  authHeaders () {
    return {
      'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1Ni....'
    }
  },
  formattedDisplay (result) {
    return result.name + ' [' + result.groupId + ']'
  }
}

Available props

Prop Type Required Default Description
source String|Function|Object|Array true data source for the results
method String 'get' http method for api requests
placeholder String 'Search' input placeholder
initialValue String|Number starting value
initialDisplay String starting display value
inputClass String|Object css class for the input div
disableInput Boolean to disable the input
name String name attribute for the value input
resultsFormatter Function<Object[]> Function to format the server data. Should return an array of objects with id and name properties
resultsProperty String property api results are keyed under
resultsValue String 'id' property to use for the value
resultsDisplay String|Function 'name' property to use for the display or custom function
requestHeaders Object extra headers appended to the request
showNoResults Boolean true To show a message that no results were found
clearButtonIcon String Optionally provide an icon css class
maxlength Number Optional max input length

Available events

Event Output Description
results Object Results returned from a search
noResults Object When no results are returned
selected Object When an item is selected
input String|Number The value when an item is selected
clear When selected results are cleared
close When the options list is closed
enter String Emits the input value when enter is pressed
nothingSelected String Emits the input value when enter is pressed and nothing was selected

Available Slots

Slot Description
firstResult list item placed before all results
lastResult list item placed at the end of the results
noResults list item shown when no results are present
Comments
  • initial commit; You can set the max input length of the search-input.

    initial commit; You can set the max input length of the search-input.

    I fixed the issue what i opened. (https://github.com/charliekassel/vuejs-autocomplete/issues/44) I hope you accept it. Please notice me if something wrong with it.

    opened by GergelyLakatos 4
  • InitialValue & initialDisplay

    InitialValue & initialDisplay

    I am trying to set an dynamic initialValue like:

                   <autocomplete 
                        :initial-value="init_val" 
                        :initial-display="init_display"                    
                        ref="autocomplete"
                        :source="get_values"
                        resultsValue="UID"
                        results-property="Items"
                        :results-display="formatted_display"
                        :request-headers="{'Authorization': $store.getters.auth_token}"
                        @selected="select_val">
                  </autocomplete>
    

    if I pass static value it works but if I try adding a dynamic variable it doesn't.

    opened by jayaVishwakarma 4
  • Can't add class to input

    Can't add class to input

    I see there's a classInput prop, but that adds a class to the div, not the input itself, so I can't get the input to match other ones on the page. This is a deal breaker for me. Otherwise, looks like a nice component.

    opened by danieljosephbrennan 4
  • Delay the search

    Delay the search

    Good day,

    First of all, I love this component, you've done well and it was exactly what we were looking for.

    I see someone has requested this already but I want to add.

    The search is definitely delayed however all requests seems to continue even though the user is still typing. Our search queries are pretty heavy and its creates a few unnecessary requests to the server.

    I'm not sure if debounce does it already but I've personally implemented something like this before but what you can do is:

    function yourKeyUpFunction(){ clearTimeout(this.searchTimeout); //where searchTimeout is a var on the component

    this.searchTimeout = setTimeout(() => { //do the search }, 200); }

    This will ensure that the last request will be sent through 200ms after the user has stopped typing.

    opened by Matthewloughton 3
  • property expected on result

    property expected on result

    after trying to populate the autocomplete this error show up;

    Error in render: "Error: "name" property expected on result but is not defined."

    "name" property expected on result but is not defined.

    the code is:

    <auto-complete
        source="http://localhost:5000/api/autocomplete/"
        input-class="is-large input"
        results-property="data">
    </auto-complete>
    

    i've tried to use a prop "name" but the same error occurs

    Another question;

    Is possible to remove the icons from input or use my own?

    opened by rafa-acioly 3
  • Slot for no result

    Slot for no result

    Hi,

    I want to modify the no result message and perform an action when user click to "nothing found" element. Can I do it with current version. Thanks

    opened by jenky 3
  • Could you add custom templating funcionality?

    Could you add custom templating funcionality?

    Hi,

    First of all, thank you for your library, it is very useful! I would need handle and show more complex objects in autocomplete list. Could you add some functionality to use custom template like here: http://jqueryui.com/autocomplete/#custom-data

    opened by martonx 3
  • HTTP headers are being converted to lower case

    HTTP headers are being converted to lower case

    authHeaders () {
        return {
          'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1Ni....'
        }
      }
    

    the above does not work correctly because Currently fetch will toLowercase() all headers. (there is some discussion here https://github.com/whatwg/fetch/issues/304 about optional disabling).

    return to axios instead

    opened by TNTLarsn 3
  • Images within results

    Images within results

    How would I show images within the result list. It only occurre as a text string

    schermafbeelding 2017-09-29 om 23 07 27

    I use :results-display="formattedDisplay"

    and

    formattedDisplay (result) {
            return "<img src='helpme.jpg'/> "+ result.name
        },
    
    opened by merijnponzo 3
  • Add support for callback to arbitrarily format the server response

    Add support for callback to arbitrarily format the server response

    We have a use case where an existing server is returning a single object with a key value pair for each autocomplete item. Since we don't have control over the response format of the endpoint, we need something that will allow us reformat the response.

    This adds an optional callback that allows for arbitrary reformatting of the data returned from the endpoint.

    opened by nick-giudici 2
  • Defining

    Defining "result-property" at sublevel

    Hi, I'm currently trying to get the autocomplete to work with an url that returns data in some way that the content I want to autocomplete against is not at the root of the response.

    Example : { "lastname":"Doe", "firstname":"John", "information":{ "grade":1, "misc": [ { "id":1, "text":"Text of the ID #1" }, { "id":2, "text":"Text of the ID #2" }, { "id":3, "text":"Text of the ID #3" }, ] } }

    In the above example I need to autocomplete against the different "text" attributes in my "information->misc" array. Can I achieve that ?

    Vinny

    opened by Vinnythetrue 2
  • Abort last request before starting another

    Abort last request before starting another

    I had an issue where sometimes requests made earlier during typing would resolve after the most recent one, which would wipe out the current results with invalid ones.

    this update cancels the previous request before starting a new one.

    opened by OverFlow636 0
  • Autocomplete=

    Autocomplete="nope" on Chrome

    According to the Issue, the fix has been done. However, currently chrome doesn't take effect on autocomplete="off" anymore. Can we modify the value to be autocomplete="nope" instead?

    opened by y-ch3n 0
  • Cannot set initial value after clearing

    Cannot set initial value after clearing

    I set an initial value like so

    
                      <autocomplete
                        ref="autocomplete"
                        :source="autoCompleteItems"
                        results-value="value"
                        results-display="text"
                        class="speciesname_autocomplete"
                        input-class="bg-white text-black border border-gray-400 hover:border-gray-500 p-2 pr-8 rounded shadow leading-tight focus:outline-none focus:shadow-outline focus:bg-gray-200"
                        @selected="setSpecies"
                        :initial-value="species"
                        :initial-display="speciesName"
                      >
                      </autocomplete>
    

    I see in dev tools that it's set, but it doesn't set any value internally.

    I've also tried using refs to change internal component data but to no avail.

    opened by NoelDavies 0
  • Replace v-model with v-on:input and v-bind:value to fix issue with au…

    Replace v-model with v-on:input and v-bind:value to fix issue with au…

    This is a fix for the Vue issue created here: https://github.com/vuejs/vue/issues/8231

    It is also listed as an issue for this repository here: https://github.com/charliekassel/vuejs-autocomplete/issues/61

    I've never created a pull request before, so let me know if there is something I am doing incorrectly that needs to be fixed.

    opened by brthiess 1
  • Unable to get input value

    Unable to get input value

     this.$root.$on("searchLocation", () => {
          console.log(this.$refs.autocomplete.xxx);
        });
    

    I want to get the value provided by the user.

    opened by MenaiAla 1
Owner
Charlie Kassel
Charlie Kassel
Autocomplete component for Vue js

vuejs-auto-complete A Vue autocomplete component npm install vuejs-auto-complete --save Usage Installation, add autocomplete component into your app i

Charlie Kassel 136 Nov 8, 2022
Feature-rich autocomplete component for Vue.js

vue-simple-suggest Simple yet feature-rich autocomplete component for Vue.js Install npm install --save vue-simple-suggest See installation guide for

Marketplace Technologies 442 Jan 4, 2023
An autocomplete/typeahead component for Vue 2 and Bootstrap 4

vue-bootstrap-typeahead A simple list-group based typeahead/autocomplete using Bootstrap 4 and Vue 2 View The Examples Installation From NPM: > npm i

Alex Urquhart 209 Nov 19, 2022
A Vue component for autocomplete email domains

vue-email-dropdown A Vue component for autocomplete email domains Features Allows passing a list of domains to be used in for the suggestions. Allows

Danny Feliz 27 Nov 24, 2022
Autocomplete Component for Vue.Js

vue-autocomplete Autocomplete Component for Vue.Js Intro Vue Autocomplete is a Vue.Js component to make some suggestions for user input. come with .vu

Naufal Rabbani 210 Jan 18, 2022
Vue 2 Component to make Autocomplete element.

Vue 2 Autocomplete Autocomplete component for Vue 2. This is a fork of vue2-autocomplete - Naufal Rabbani [email protected] Install You can imp

Eduardo Aguad 0 Oct 12, 2017
A Vue Autocomplete component with accessibility and simplicity in mind.

VueCompleter A Vue Autocomplete component with accessibility and simplicity in mind. Installation npm install vue-completer or yarn add vue-completer

Tom Elliott 3 Nov 8, 2020
vue autoComplete component

vueto-complete vue autoComplete component Index Features Installation Examples Props Slots Events Styling LICENSE Features Supports full control over

Ahmed Abdallah 16 Jan 10, 2022
Google Autocomplete Vue Componet

Google Autocomplete I am sharing this component because I was overwhelmed by complicated examples to achieve this simple job. So, I will try to be as

Gustavo Ocanto 275 Aug 29, 2022
🧱 Very Downshift like autocomplete solution for Vue

Vue Combo Blocks ?? Provides all the building blocks needed for accessible autocomplete, combobox, or typeahead component. A very Downshift like autoc

Simeon Kerkola 17 Jul 7, 2022
A simple tags input with typeahead (autocomplete) built with Vue.js 2.

Vue Tags Input v4 Forked from voerro/vue-tagsinput A simple tags input with typeahead built with Vue.js 2. Installation via NPM npm i @seriouslag/vue-

Landon Gavin 1 Nov 6, 2021
A simple tags input with typeahead (autocomplete) built with Vue.js 2.

Voerro Vue Tags Input v2 A simple tags input with typeahead built with Vue.js 2. Live Demo Installation via NPM npm i @voerro/vue-tagsinput --save-dev

null 0 Jul 8, 2021
A better vim plugin for stylus, including proper and up-to-date syntax highligting, indentation and autocomplete

Vim Stylus Vim + Stylus = fast, effective and convenient CSS workflow! Features All HTML5 tags and CSS3 props are covered Correct highlighting for int

Ilia Loginov 48 Dec 28, 2022
🔍 Vue autosuggest component.

vue-autosuggest ?? Autosuggest component built for Vue. Table of Contents Examples Features Installation Usage Props Inspiration Contributors LICENSE

Darren Jennings 599 Dec 31, 2022
A configurable & lightweight Vue wrapper component that enables

A configurable & lightweight Vue wrapper component that enables "out of the box" email autocomplete/suggestions on input elements.

James Wylie 28 Jul 19, 2022
Mention component for Vue.js

vue-mention Mention popper for input and textarea Documentation Sponsors Quick start <script> import { Mentionable } from 'vue-mention' const users =

Guillaume Chau 462 Dec 22, 2022
🔍 Autosuggest component built for Vue

vue-autosuggest ?? Autosuggest component built for Vue. Table of Contents Examples Features Installation Usage Props Inspiration Contributors LICENSE

Алексей Мышкин 0 Dec 12, 2019
A simple modular Vuejs component that autosuggest input from a dyanamic or static data querying.

v-autosuggest A simple modular Vuejs component that autosuggest input from a dyanamic or static data querying. Table of contents Installation Usage Pr

soraino 9 Nov 24, 2022
A simple tag component with typeahead

v-tag-suggestion A simple tag component with typeahead ⌨️ Install via npm npm install vue-tag-suggestion Import and register where you want to use imp

Maheshkumar 39 Mar 26, 2022