• Stars
    star
    207
  • Rank 189,769 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 9 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Autocomplete Component for Vue.Js

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

More Repositories

1

vue2-loading-bar

Simplest Youtube Like Loading Bar Component For Vue 2. http://bosnaufal.github.io/vue2-loading-bar/
JavaScript
269
star
2

vue-mini-shop

Mini Online Shop Built With Vue JS
JavaScript
267
star
3

vue2-scrollbar

The Simplest Pretty Scroll Area Component with custom scrollbar for Vue 2. https://bosnaufal.github.io/vue2-scrollbar
Vue
235
star
4

vue2-autocomplete

Vue 2 Component to make Autocomplete element.
Vue
234
star
5

vue-simple-pwa

Simple Progressive Web App Built with Vue Js. https://bosnaufal.github.io/vue-simple-pwa
CSS
196
star
6

vuex-saga

Better Vuex Action To Simplify Your Async Flow Process And Code Testing
JavaScript
159
star
7

react-file-base64

React Component for Converting File to base64
JavaScript
158
star
8

vue-loading-bar

Youtube Like Loading Bar Component for Vue.js
JavaScript
139
star
9

vue-scrollbar

The Simplest Scroll Area Component with custom scrollbar for Vue Js. https://bosnaufal.github.io/vue-scrollbar/
Vue
118
star
10

react-simple-pwa

Simple Progressive Web App Built with React Js. https://bosnaufal.github.io/react-simple-pwa
JavaScript
112
star
11

vue-freeze

Simple state management whitout bloating API and Concept for Vue.js.
JavaScript
74
star
12

react-scrollbar

The Simplest Scroll Area Component with custom scrollbar for React JS. https://bosnaufal.github.io/react-scrollbar
JavaScript
71
star
13

vue-simple-store

Store Organizer To Simplify Your Stores
JavaScript
67
star
14

vue-image-compressor

Vue Component To Compress Image Files Via Client Side. https://bosnaufal.github.io/vue-image-compressor
Vue
56
star
15

vue-file-base64

Vue Component for Convert File to base64
Vue
49
star
16

javascript-sabuk-putih

Modal Awal Belajar Fundamental Javascript Untuk Mendalami React JS, Vue JS, Angular JS, ataupun Node JS
HTML
49
star
17

vue-ripple

Vue Component to Make Google Material Design Ripple Effect. http://bosnaufal.github.io/vue-ripple/
Vue
48
star
18

terbilang-js

Convert Number Into Indonesian Words By Frontend's way
JavaScript
45
star
19

vue-click-outside

Vue Directive to make a click outside event
JavaScript
41
star
20

react-loading-bar

Simplest Youtube Like Loading Bar Component For React Js. http://bosnaufal.github.io/react-loading-bar/
JavaScript
40
star
21

vue-starter

Simple Vue Js Starter for single page application with Vuex and Vue Router
JavaScript
36
star
22

react-ripple

React Component to Make Google Material Design Ripple Effect. http://bosnaufal.github.io/react-ripple/
HTML
33
star
23

vue-testing

Let's make Vue Testing And Mocking Become Easier And Much Fun
JavaScript
31
star
24

secure-local-storage

Javascript Library to make a secure local storage with encryption
JavaScript
28
star
25

click-outside-js

Standalone javascript library to make click outside event. https://bosnaufal.github.io/click-outside-js/
HTML
18
star
26

react-image-compressor

React Component To Compress Image Files Via Client Side. https://bosnaufal.github.io/react-image-compressor
JavaScript
18
star
27

react-starter

Simple starter for React Js project. Completely built with simple configuration
JavaScript
16
star
28

css-itu-mudah

Mini ebook untuk belajar CSS mulai dari dasar
Vue
14
star
29

vue2-starter

Simple Vue 2 Starter for single page application with Vuex and Vue Router
JavaScript
11
star
30

vue-move-dom

Vue Directive to move the DOM without losing all the VM data, event, etc. it's Adopted from https://github.com/rhyzx/vue-transfer-dom
JavaScript
7
star
31

counting-day

Mini library to count your day
JavaScript
6
star
32

javascript-for-all

Javascript Untuk Pemula, Javascript Untuk Semua: Basic Examples
JavaScript
5
star
33

micro-blogging-vue

Micro Blogging System Built with Vue.js
JavaScript
5
star
34

terbilang-vue

Vue Filter to Convert Number into Indonesian words.
5
star
35

fake-api

Javascript library to make Fake API like a Real API. YOU DON'T NEED SERVER!
JavaScript
4
star
36

vue-calc-input

Vue directive to make a calculator input behavior. Implementation of https://github.com/BosNaufal/readable-number
JavaScript
4
star
37

mage-its-pwa

Boilerplate dan Hasil Jadi untuk Workshop Mage ITS tentang Progressive Web App
JavaScript
4
star
38

readable-number

Simple Javascript function to make an integer become readable and vice versa.
JavaScript
4
star
39

argvalid

Make Sure That Your Variable Is Valid. It's Inspired By https://vuejs.org/v2/guide/components.html#Props
JavaScript
4
star
40

meetups

Kumpulan Kodingan Meet up
JavaScript
3
star
41

virtual-element

Simple Reactive Web Component With Virtual DOM for building user interfaces | https://bosnaufal.github.io/virtual-element
JavaScript
2
star
42

runner-js

Better Async Handler To Simplify Your Async Flow Process And Code Testing
JavaScript
1
star
43

vue-freeze-todomvc

Vue Freeze Todo MVC Example
JavaScript
1
star
44

lazy-image

Standalone Javascript Library to lazy load the image. You can use it without jquery~
JavaScript
1
star
45

vuedova

Tool for developing Cordova with Vue Js
JavaScript
1
star
46

test-checkbox

Simple Checkbox with custom label component
Vue
1
star
47

react-click-outside

Click outside event in React Js
JavaScript
1
star
48

react-calc-input

A React Component to make a calculator input behavior
JavaScript
1
star
49

vue-readable-number

Vue Filter to make an integer become readable and vice versa. The Vue implementation of https://github.com/BosNaufal/readable-number
JavaScript
1
star
50

vue-boilerplate

Vue Boilerplate inspired by https://github.com/mxstbr/react-boilerplate
JavaScript
1
star
51

cordova-iframe-generator

Base Generator for cordova-iframe
JavaScript
1
star
52

secure-string-js

Simple Javascript Encryptor / Decryptor to make your string or variable become secure
JavaScript
1
star
53

online-shop-starter

Super Simple Online Shop Starter. https://github.com/BosNaufal/vue-mini-shop
CSS
1
star