Autocomplete Component for Vue.Js

Overview

vue-autocomplete

Autocomplete Component for Vue.Js

vue Autocomplete component

Intro

Vue Autocomplete is a Vue.Js component to make some suggestions for user input. come with .vue and .js file make it easier to be installed for your next project.

Vue Autocomplete is inspired by aFarkas remote-list Jquery Plugin. crafted with simple javascript (Also ES6 support), and doesn't require Jquery.

Features

  • full customizable
  • Already, Complete callback event
  • Included .vue file
  • well commented code
  • writen in ES6 (Still in Learning now)
  • doesn't require any javascript libs, except Vue.Js
  • Support multiple autocomplete components

Install

Simply include the vue-autocomplete.js to your HTML or web page file, next to Vue.Js. You can take a peek an example at example.html. And don't forget to include vue-autocomplete.css file when you choose this way.

Or

You can import vue-autocomplete.vue to your vue component file like this and process it with your preprocessor.

import autocomplete from ./vue-autocomplete.vue
// Or
var autocomplete = require('./vue-autocomplete.vue');

Usage

minimal:

<autocomplete
  name="people"
  url="http://localhost:3000/remote-list/klien"
  anchor="value"
  label="label"
  model="vModelLike">
</autocomplete>

Full Example:

<autocomplete
  id="input__id-optional"
  class="input_class optional"
  name="people"
  placeholder="Type Here"
  url="http://localhost:3000/remote-list/klien"
  param="q"
  limit="5"
  anchor="value"
  label="label"
  model="vModelLike">
</autocomplete>

Additional parameters

If you need to pass more parameters in url, use Computed Properties (https://vuejs.org/guide/computed.html) :

Example:

            param: function () {
                return 'foo=' + this.bar + '&q';
            }
      }```

in component change ```param ="q" for :param="param" ```

## Props

##### `name` (*) : Component Identity
will use for Identify the autocomplete component. for multiple use purpose.

<br/>

##### `url` (*) : Ajax URL to fetch
the URL must be active (not from file). the component will fetch JSON from this URL with (default : `q`) query. like:
`http://some-url.com/API/list?q=`.
There are no filter and limit action inside the component. So, do it in your API logic.

<br/>

##### `param` : name of the search query in Ajax call. default ( q )
<br/>

##### `min` : Minimum input typed chars before performing the search query. default ( 3 )
<br/>

##### `limit` : amount of query limit in ajax call.
example, `limit=5` the AJAX URL will be `http://some-url.com/API/list?q=blabla&limit=5`

<br/>

##### `anchor`(*) : Anchor for Suggestion list
Anchor for listing suggestions. Example `anchor="name"` will get the name object of your JSON data for suggestion listing like ("Bambang", "Sukijan", "Bejo") in the demo above.

<br/>

##### `label` : Description for Suggestion list
For description to your suggestion. the uses is like `anchor` props but for the description of each suggestion. like ("Alamat", "alamat sesuai ktp", "alamat") in the demo above. not required but if it's null the component will look bad.

<br/>

##### `model` : v-model like for your component
v-model like of component to make two data binding working like usual.

<br/>

##### `placeholder` : input placeholder (optional)
<br/>

##### `class` : Component Class (optional)
will generate an class for input element. this only for the input element in autocomplete.

<br/>

##### `id` : Component Id (optional)
will generate an Id for input element.

<br/>

## Callback Events
Make an events in component's parent than the [vue-autocomplete](https://github.com/BosNaufal/vue-autocomplete) component will dispatch some events to it.
```javascript
...
events: {

  /**
  *  Global Autocomplete Callback Event
  *
  *  @event-name autocomplete:{event-name}
  *  @param {String} name name of auto
  *  @param {Object} data
  *  @param {Object} json - ajax-loaded only
  */

  // Autocomplete on before ajax progress
  'autocomplete:before-ajax': function (name,data){
    console.log('before-ajax',name,data);
  },

  // Autocomplete on ajax progress
  'autocomplete:ajax-progress': function(name,data){
    console.log('ajax-progress',data);
  },

  // Autocomplete on ajax loaded
  'autocomplete:ajax-loaded': function(name,data,json){
    console.log('ajax-loaded',data,json);
  },

  // Autocomplete on focus
  'autocomplete:focus': function(name,evt){
    console.log('focus',name,evt);
  },

  // Autocomplete on input
  'autocomplete:input': function(name,data){
    console.log('input',data);
  },

  // Autocomplete on blur
  'autocomplete:blur': function(name,evt){
    console.log('blur',evt);
  },

  // Autocomplete on show
  'autocomplete:show': function(name){
    console.log('show',name);
  },

  // Autocomplete on selected
  'autocomplete:selected': function(name,data){
    console.log('selected',data);
    this.data = data;
  },

  // Autocomplete on hide
  'autocomplete:hide': function(name){
    console.log('hide',name);
  },


  /**
  *  Spesific Autocomplete Callback Event By Name
  *
  *  @event-name autocomplete-{component-name}:{event-name}
  *  @param {String} name name of auto
  *  @param {Object} data
  *  @param {Object} json - ajax-loaded only
  */

  // Autocomplete on before ajax progress
  'autocomplete-people:before-ajax': function(data){
    console.log('before-ajax-people',data);
  },

  // Autocomplete on ajax progress
  'autocomplete-people:ajax-progress': function(data){
    console.log('ajax-progress-people',data);
  },

  // Autocomplete on ajax loaded
  'autocomplete-people:ajax-loaded': function(data,json){
    console.log('ajax-loaded-people',data,json);
  },

  // Autocomplete-people on focus
  'autocomplete-people:focus': function(evt){
    console.log('focus-people',evt);
  },

  // Autocomplete-people on input
  'autocomplete-people:input': function(data){
    console.log('input-people',data);
  },

  // Autocomplete-people on blur
  'autocomplete-people:blur': function(evt){
    console.log('blur-people',evt);
  },

  // Autocomplete-people on show
  'autocomplete-people:show': function(){
    console.log('show-people');
  },

  // Autocomplete-people on selected
  'autocomplete-people:selected': function(data){
    console.log('selected-people',data);
  },

  // Autocomplete-people on hide
  'autocomplete-people:hide': function(){
    console.log('hide-people');
  },

}

Clear Method

If you need to Clear or Netralize your autocomplete, You can simply make some refs then call a method named clearInput(). You can take a look at the Example :

<button @click="clearAutocomplete">Clear</button>
<autocomplete
  id="input__id-optional"
  class="input_class optional"
  name="people"
  placeholder="Type Here"
  url="http://localhost:3000/remote-list/klien"
  param="q"
  limit="5"
  anchor="value"
  label="label"
  model="vModelLike"
  v-ref:my-autocomplete>
</autocomplete>
  // ... another vue scope

  methods: {
    clearAutocomplete() {
      this.$refs.myAutocomplete.clearInput()
    }
  },

  // ...

Thank You for Making this helpful for your projects~

Hopefully this can be usefull for the others.

Let's talk about some projects with me

Just Contact Me At:

License

MIT Copyright (c) 2016 - forever Naufal Rabbani

Comments
  • Ability to clear input after selected

    Ability to clear input after selected

    Hi There,

    With the events supplied, I am unable to clear the input field once the user has selected the option:

    ...
    model="new_material"
    ...
    

    and in the event:

    events:{
        'autocomplete-myautocomplete:selected': function(data){
            console.log(data);
            this.new_material=''; //does not clear the input field
        }
    },
    
    opened by roarkmccolgan 8
  • The demo example is not working

    The demo example is not working

    Hi thanks for this component

    I am tring to use this in my project but I am not sure how the Json should be formatted is there a rule? a vue rule? I am pretty new to vue.js

    Can you help me?

    thanks for help

    opened by falko189 3
  • Problem with Vue Js 2.0

    Problem with Vue Js 2.0

    Hello

    When I intent to use this package with Vue Js 2.0.

    I'm getting a lot of errors: like

    [Vue warn]: class="autocomplete transition autocomplete-{{ name }}": Interpolation inside attributes has been deprecated. Use v-bind or the colon shorthand instead.

    id="autocomplete-{{ name }}": Interpolation inside attributes has been deprecated. Use v-bind or the colon shorthand instead.

    - avoid using JavaScript keyword as property name: "class" in expression :class="class"

    opened by ludioao 2
  • Added customizable minimum length before performing the query

    Added customizable minimum length before performing the query

    I needed this feature to limit server queries. I see I'm not the only one, this PR fixes https://github.com/BosNaufal/vue-autocomplete/issues/7 needs.

    opened by phaberest 2
  • How to set input class (bootstrap)

    How to set input class (bootstrap)

    Hello, can you help me how to set input class for autocomplete component? I'm using this component, set class as "form-control".

    <autocomplete
                  url="/api/product/autocomplete"
                  anchor="nama"
                  label="barcode"
                  class="form-control"              
                  :on-select="getSelectedProduct">
    </autocomplete>
    

    Its become like this: image

    and the class was added on the div, not on input: image

    Thanks,

    opened by heribertusk 1
  • Disable browser autocomplete to avoid conflicts

    Disable browser autocomplete to avoid conflicts

    I've noticed some issues with browser-based autocomplete (specifically in latest Chrome) competing with the scripted autocomplete. It seems to require that you actually click the result twice to make the selection stick if the entry matches a browser autocomplete result.

    Setting <input type="text" autocomplete="off"... fixed it for me.

    Note: I tried to setup gulp to make a pull request for this, but gulp build-js seemed to be changing more than it should in build.js. Maybe because of version differences. Also, I couldn't get it to update vue-autocomplete.js and vue-autocomplete.min.js. I'm not really a JS developer so I'm probably just missing something obvious. I'd be happy to submit a PR if anyone has any advice for how to properly build the project. Thanks.

    opened by adamcrown 1
  • Minimum length required?

    Minimum length required?

    Is there a way to make a minimum length required before searching or hitting the url??

    And for some odd reason, I cannot seem to get my results to pop up even though the Network tab is showing results are showing from the response...

    <autocomplete
                        id="item_search"
                        class="form-control"
                        name="item_search"
                        placeholder="Start typing item name"
                        url="{{ url('api/items') }}"
                        param="name"
                        limit="10"
                        anchor="value"
                        label="label"
                        model="item_search">
                    </autocomplete>
    
                  <pre>@{{ items | json }}</pre>
    

    I'm doing this:

        'autocomplete-item_search:before-ajax': function(data){
            console.log(data);
        },
    

    and nothing is logging...

    Thanks for any help.

    opened by IntellectProductions 1
  • Mobile browsers - fix

    Mobile browsers - fix

    You can not use v-model for some mobile browsers (like Chrome for android) in this case. I've spent a few hours before solving this. I've found that you couldn't type in the input when using mobile browsers with virtual keyboard - simply after typing one letter input was cleared instantly.

    It looks like there's some problem with emitting an event in Vue.

    More info:

    https://github.com/vuejs/vue/issues/9299

    opened by radoslawkoziol 0
  • Transition not working with vue js 2

    Transition not working with vue js 2

    I receive the following issue by using your plugin:

    vue-autocomplete.min.js:8 Uncaught TypeError: Vue.transition is not a function(anonymous function) @ vue-autocomplete.min.js:8
    

    According to https://vuejs.org/v2/guide/migration.html#Vue-transition-for-Reusable-Transitions-replaced this is deprecated in Vue JS 2

    opened by DanielSiepmann 1
  • Unique name for multiple instances

    Unique name for multiple instances

    Hi There,

    When using in a loop: v-for="(optionKey, option) in myOptions")

    I am unable to use the current "optionKey" in naming each instance:

    <vue-autocomplete
        name="material_{{optionKey}}"
        param="name"
        url="/api/materials"
        anchor="name"
        label="Material"
        limit="5"
        model="material"
        class="form-control input-sm"
    </vue-autocomplete>
    

    same problem for binding to existing data object: model="{{option}}"

    It uses it as a string

    opened by roarkmccolgan 0
Owner
Naufal Rabbani
Either Web Developer Live In Indonesia Who Love to Write and Code. Do You have any open source project which you want me to work on? Just contact me soon!
Naufal Rabbani
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