1.1.10 • Published 5 years ago

vue-autocompletion v1.1.10

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

Vue Autocompletion

npm (scoped) npm MIT

Installation via NPM

First

Install via NPM

npm i vue-autocompletion --save-dev

or

npm i  vue-autocompletion --save

Second

Require in your project:

var VueAutocompletion = require('vue-autocompletion');

or ES6 syntax:

import VueAutocompletion from 'vue-autocompletion'

Third

You can register the component globally:

Vue.component('autocomplete', VueAutocompletion);

Or locally in a single Vue component:

 components: { 'autocomplete':VueAutocompletion },

All Available Props for vue-autocompletion

PropTypeDefaultDescription
keyFieldStringidid for the hidden input / your expected object key i.e. id:xxx
valueFieldStringnamethe value that is set for your expected object value i.e. name:xxx
remoteKeyString*keyFieldthe value that is set for your expected object key i.e. {id:xxx}
remoteValueString*valueFieldthe value that is set for your expected object value i.e. {name:xxx}
remotePrimaryValueString-if defined it will look for this as highest choice in search from remote. Difficult to explain but remote data may be dynamic and sometimes may include cityName other times countryName so remoteKey would be preferred in this instance cityName if not found then it will fall back to remoteValue which be countryName as other choice
remoteValueSelectString-the actual value to select if remoteValue is shown as selectable item {what appears after selection} is also set as expected object value
clazzString-css classes to load if additional css styling needed
returnPromiseBooleanfalsereturn entire object - this is for more complex objects that have many other things you need to do with returned data
placeholderStringnamethe value that is set for a blank auto complete box
selectedObject{}The actual selected object when user chooses one of drop down - emited back to parent call overwriting parent key/value fields
nameString-The name of select field must match object name that is being saved for validation to work or valueField name
searchLengthNumber3Amount of characters before triggering dropdown
itemsArray[]parent's array of selectable objects - can be fixed or db driven - key presses by user trigger list to update
isAsyncBooleanfalseunused feature came with original guide
disabledBooleanfalseset to true to disable selectable area
readonlyBooleanfalseset to true to make area non selectable and readonly
overrideClearFunctionBooleanfalseset to true to override html 5 x that appears in input and use plugins version. This may be needed depending on vue object modelling.
additionalPropertiesArray[]A list of additional objects to set or clear in one go refer to example 8 [{valueField:'countryName', remoteValue:'countryName', keyField:'countryCode', remoteKey:'countryCode'}, {objectName:'subObject', keyField:'countryId', remoteKey:'countryCode' }, {valueField:'state'}, {keyField:'countryId', remoteKey:'countryCode' }, ]
setTimeOutBooleanfalseenable setTimeOut not needed for validation call - non validation may be needed
timeOutPeriodNumber300Time out in milliseconds default should be sufficient

All Available Props for vue-autocompletion-valid (above + below)

PropTypeDefaultDescription
validationErrorsArray[]returns any vee-validate validation issues back to caller
validationString-the validation types required i.e. 'requiredxx'

Events

EventDescription
@key-pressFired when the input text changes
@search-valueif v-model directive declared then not required but if set allows you to manipulate locally from set selected value field
@search-keyif v-model directive declared then not required but if set allows you to manipulate locally from set selected key field
@return-promiseNot required but if set won't manipulate parent object instead return the full object from remote selection back to you, this contains the entire object selected. It may have many other values you need to update page with.
@method-usedreturns a string of mouse or keyboard if they selected auto complete with mouse or keyboard if they used tab up down arrows and enter

Usage

Working Demo project (needs to be downloaded run)

YouTube demo video

Example 1: Basic
Example 2: vue-autocompletion-valid: Validation using vee-validate
Example 3: Remote object sometimes has additional data which should be selected
Example 4: Remote object sends 2 values one to search or show in search box and one to actually select
Example 5: Return promise and deal with selected item manually
Example 6: v-model directive not defined @search-value @search-key used instead
Example 7: Multiple dynamic select box with add remove function : Demo of method-used
Example 8: additionalProperties and auto complete one to auto complete another

Changelog

Credits

Filipa Lacerda

This code originated from above posting, I tried to find the github source for this project but ended up finding it reused everywhere. I had a look at some of the existing auto complete plugins and at the time building from scratch felt most suited to dynamics of it's requirements. Original version by Filipa did most but I needed additional logic to make it work even more dynamically extensively. One of the main issues I found when testing existing auto completes was when an invalid entry is entered the entry persists on input area and there are 2 specific setTimeouts within the js file to try capture real outcome after a race condition.

1.1.9

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.10

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago