Giter Site home page Giter Site logo

kazanexpress / vue-simple-suggest Goto Github PK

View Code? Open in Web Editor NEW
459.0 9.0 76.0 2.75 MB

Feature-rich autocomplete component for Vue.js

Home Page: https://kazanexpress.github.io/vue-simple-suggest/

License: MIT License

Vue 78.34% JavaScript 20.33% EJS 1.33%
vue vuejs suggestions autocomplete-component search suggest autocomplete autocomplete-suggestions vue-components customizable

vue-simple-suggest's Introduction

vue-simple-suggest

Simple yet feature-rich autocomplete component for Vue.js

npm live demo github repo vue-awesome link npm All Contributors

Install

npm install --save vue-simple-suggest

See installation guide for more options.

Table of contents

What is it

This is a simple yet feature-rich suggestion/autocomplete component for Vue.js.

Actually, it's so feature rich, that it's possible to do crazy stuff with it, like

  • Imitating drop-downs and drop-down menus
  • Turn suggestions list into an actual suggestions table
  • Work with ANY type of custom input passed (like type=button, radio and etc.)
  • ... And many more things

And, as a bonus, it is very light.

Features

  • v-model support.
  • Automatic accessibility attributes (WAI-ARIA complete)
  • Switching v-model type (select/input).
  • Custom input element through default slot.
  • Custom list items through named scoped slots.
  • All HTML5-valid props for default input element are provided (type, tabindex and etc...).
  • Customizable keyboard controls.
  • Rich and simple API.
  • CSS classes for quick and easy restyling.
  • Many build variants to choose from.
  • Flexible and customizable component design.
  • Optional polyfills for IE importable from the lib.

All of the props, events and slots are OPTIONAL for this component, so it can be used without any configuration at all.

New features?

If you feel that something important is missing (or found a bug) - feel free to create an issue. :)


Examples:

To use the component just install via NPM:

npm install --save vue-simple-suggest

Then, in your Vue.js component/page do the following...

Simple example

If you need to suggest things from a static array:

<!-- Some component.vue -->
<template>
  <vue-simple-suggest
    v-model="chosen"
    :list="simpleSuggestionList"
    :filter-by-query="true">
<!-- Filter by input text to only show the matching results -->
  </vue-simple-suggest>

  <br>

  <p>Chosen element: {{ chosen }}</p>
</template>

<script>
  import VueSimpleSuggest from 'vue-simple-suggest'
  import 'vue-simple-suggest/dist/styles.css' // Optional CSS

  export default {
    components: {
      VueSimpleSuggest
    },
    data() {
      return {
        chosen: ''
      }
    },
    methods: {
      simpleSuggestionList() {
        return [
          'Vue.js',
          'React.js',
          'Angular.js'
        ]
      }
    }
  }
</script>

Async example

If you're dealing with async data from server (example using https://swapi.co/):

<!-- Some component.vue -->
<template>
  <vue-simple-suggest
    v-model="chosen"
    display-attribute="name"
    value-attribute="url"
    :list="getSuggestionList"
  ></vue-simple-suggest>

  <br>

  <p>Chosen element: {{ chosen }}</p>
</template>

<script>
  import VueSimpleSuggest from 'vue-simple-suggest'
  import 'vue-simple-suggest/dist/styles.css' // Optional CSS

  export default {
    components: {
      VueSimpleSuggest
    },
    data() {
      return {
        chosen: ''
      }
    },
    methods: {
      // Function returning a promise as a factory for suggestion lists.
      //
      // vue-simple-suggest calls it automatically when an update to the list is needed,
      // no need for watchers here!
      getSuggestionList() {
        return fetch('https://swapi.co/api/people', { method: 'GET' })
          .then(response => response.json())
          .then(json => json.results); /*
          returns a promise with a list of star-wars characters
        */
      }
    }
  }
</script>

For a more advanced example (using wikipedia search) see our example source.


Installation

NPM

npm install --save vue-simple-suggest
# or
yarn add vue-simple-suggest

Unpkg

If including via this method - the component will automatically install itself.

<!-- UMD Component, async/await polyfills through promises -->
<script type="text/javascript" src="https://unpkg.com/vue-simple-suggest"></script>
<script type="text/javascript" src="https://unpkg.com/[email protected]"></script>
                                                              <!-- Specific version -->

<!-- CSS -->
<link rel="stylesheet" href="https://unpkg.com/vue-simple-suggest/dist/styles.css">

<!-- If you need polyfills, use IIFE verision below -->
<!-- IIFE build includes ALL polyfills: Object.assign, Promises, Generators, Async/Await! -->
<script type="text/javascript" src="https://unpkg.com/vue-simple-suggest/dist/iife.js"></script>

Importing

/// ESNext (original code, no pollyfills, single-file .vue component, css included)
import VueSimpleSuggest from 'vue-simple-suggest/lib'
///

/// ES6 (async polyfills)
import VueSimpleSuggest from 'vue-simple-suggest'
// or, if you have problems importing:
import VueSimpleSuggest from 'vue-simple-suggest/dist/es6'
///

/// ES7 and above (no polyfills)
import VueSimpleSuggest from 'vue-simple-suggest/dist/es7'
///

/// CommonJS (async, arrow-functions and promises are polyfilled)
const VueSimpleSuggest = require('vue-simple-suggest')
// or, if you have problems importing:
const VueSimpleSuggest = require('vue-simple-suggest/dist/cjs')
///

// Optional - import css separately with css loaders:
import 'vue-simple-suggest/dist/styles.css'

Polyfills

New in v1.8.3

vue-simple-suggest comes with minimal optional polyfills for IE11+ - Object.assign, Element.prototype.closest and Element.prototype.matches. You can import them like this:

import 'vue-simple-suggest/lib/polyfills';
// or
require('vue-simple-suggest/lib/polyfills');

Usage

Globaly:

// You don't need to do it, if including via <script> (umd, iife)
Vue.component('vue-simple-suggest', VueSimpleSuggest)

In single-file .vue components:

<script>
  import VueSimpleSuggest from 'vue-simple-suggest'
  import 'vue-simple-suggest/dist/styles.css' // Using a css-loader

  export default {
    components: {
      VueSimpleSuggest
    }
  }
</script>

Build Setup

# clone the repo
git clone https://github.com/KazanExpress/vue-simple-suggest.git
cd ./vue-simple-suggest

# install dependencies
npm install

# serve example with hot reload at localhost
npm run dev

# build example & readme for static serving
npm run docs

Default Controls

New in v1.2.0

These are default keyboard shortcuts.

Can be customized with the controls prop. All fields in this controls object are optional.

Default scheme:

Key (key code) Description
Escape (27) If the suggestions list is shown - hide it. Defined by hideList property.
ArrowDown (40) If the suggestions list is hidden - show it. Defined by showList property.
ArrowUp (38) / ArrowDown (40) Cycle (hover) through suggestions. Defined by selectionUp/selectionDown properties respectfully.
Enter (13) If the list is shown - chooses the highlighted element. Defined by select property.
(Ctrl/Shift) + Space (32) Select the first element in the list. Defined by autocomplete property. Works with Ctrl modifier key or Shift modifier key.
(Ctrl/Shift) + Enter (13) Same as previous, but also hides the suggestions list.

JS object:

{
  selectionUp: [38],
  selectionDown: [40],
  select: [13],
  showList: [40],
  hideList: [27],
  autocomplete: [32, 13]
}

Component API

TLDR

Click to expand
<!-- Ref to access the API, v-model for efficient query binding -->
<vue-simple-suggest ref="vueSimpleSuggest" v-model="model"
  value-attribute="id"
  display-attribute="title"
  mode="input"
  placeholder="placeholder!!!"
  :list="getListFunction"
  :max-suggestions="10"
  :min-length="3"
  :debounce="100"
  :destyled="false"
  :remove-list="false"
  :filter-by-query="false"
  :filter="customFilterFunction"
  :value="defaultValue"
  :nullable-select="true"
  :controls="{
    selectionUp: [38, 33],
    selectionDown: [40, 34],
    select: [13, 36],
    showList: [40],
    hideList: [27, 35],
    autocomplete: [32, 13],
  }"
  @input="onInputEvent"
  @select="onSuggestSelect"
  @hover="onSuggestHover"
  @focus="onFocus"
  @blur="onBlur"
  @request-start="onRequestStart"
  @request-done="onRequestDone"
  @request-failed="onRequestFailed"
  @show-list="onShowList"
  @hide-list="onHideList"
>
  <!-- v-model on input itself is useless -->
  <input class="optional-custom-input">

  <!-- Appears o top of the list -->
  <template slot="misc-item-above" slot-scope="{ suggestions, query }">
    <div class="misc-item">
      <span>You're searching for {{ query }}.</span>
    </div>
    <div class="misc-item">
      <span>{{ suggestions.length }} suggestions are shown...</span>
    </div>
    <hr>
  </template>

  <div slot="suggestion-item" slot-scope="{ suggestion }" class="custom">{{ suggestion.title }}</div>

  <!-- Appears below the list -->
  <div class="misc-item" slot="misc-item-below" slot-scope="{ suggestions }" v-if="loading">
    <span>Loading...</span>
  </div>
</vue-simple-suggest>

CSS class structure

If there's a need to customize the appearance of the component, here's the internal class-structure:

// .designed is applied only if `destyled` prop is false.
.vue-simple-suggest.designed.focus // .focus is applied whenever the component is focused.
  .input-wrapper
    .default-input // Replaced with your custom input if default slot is provided.
  .suggestions // Also has transition classes, see below.
    .suggest-item

If you wish to use your existing classes, or frameworks like Bootstrap you can inject your own classes using the 'styles' prop:

<!-- Some component.vue -->
<template>
  <vue-simple-suggest
    v-model="chosen"
    :list="simpleSuggestionList"
    :styles="autoCompleteStyle"
    :destyled=true
    :filter-by-query="true">
  </vue-simple-suggest>
</template>

<script>
  ...
  export default {
    ...
    data() {
      return {
        autoCompleteStyle : {
          vueSimpleSuggest: "position-relative",
          inputWrapper: "",
          defaultInput : "form-control",
          suggestions: "position-absolute list-group z-1000",
          suggestItem: "list-group-item"
        }
      }
    },
    ...
  }
</script>`

<style lang="scss">
.z-1000 {
  z-index: 1000;
}
.hover {
  background-color: #007bff;
  color: #fff;
}
</style>

Scheme:

Property Description
vueSimpleSuggest Additional classname for component's root element.
inputWrapper Additional classname for .input-wrapper element.
defaultInput Additional classname for input element if no custom input component is given.
suggestions Additional classname for suggestions list ul element.
miscItemAbove Classname for misc-item-above slot wrapper (li element itself).
suggestItem Additional classname for suggestion item li element.
miscItemBelow Classname for misc-item-below slot wrapper (li element itself).

Transitions

New in v1.8.0

You can also define custom list transitions by defining css rules for the transition named vue-simple-suggest on the .suggestions div:

.suggestions {
  /* It's improtant to have a cpecific pivot point for transition:*/
  opacity: 1;
}

.vue-simple-suggest-enter-active.suggestions,
.vue-simple-suggest-leave-active.suggestions {
  /* Transition length here:*/
  transition: opacity .2s;
}

.vue-simple-suggest-enter.suggestions,
.vue-simple-suggest-leave-to.suggestions {
  /* Transition rule for "disengaged" element:*/
  opacity: 0;
}

API definitions

Props

Name Type Default Description
controls v1.2.0 Object See default controls Determines the keyboard shortcuts in key-codes (for browser-compatibility purposes). Arrays provide the ability to assign multiple keys to one action. Consists of 5 array fields: selectionUp, selectionDown, select, hideList and autocomplete, all of which are optional.
max-suggestions Number 10 The maximum amount of suggestions to display. Set to 0 for infinite suggestions.
min-length Number 1 The minimum amount of symbols in input to trigger suggestion list. vue-simple-suggest starts behaving as a dropdown menu, if the value is 0.
display-attribute String 'title' The property in a suggestion object to display in a list. Supports dotted paths.
value-attribute String 'id' The property in a suggestion object to use as a unique key. Supports dotted paths.
list Function or Array () => [] The array provider function, must accept a query as its only argument. Can return an array or a promise. Can be async. The component behaves as a simple input without this function.
debounce Number 0 Determines the list debounce (a time between the input event and a function execution).
destyled Boolean false Whether to cancel the default styling of input and suggestions list.
styles v1.8.0 Object {} CSS classes to attach with current component style.
remove-list Boolean false If true - the suggestion list will be always hidden.
filter-by-query Boolean false Whether to filter the resulting suggestions by input's text query (make it a search component).
filter Function - A custom function for filtering the suggestion results that accepts a single item and a query to filter by as its 2 arguments. Used only if filter-by-query is set to true.
mode v1.4.0 String 'input' The v-model event. Determines the event, that triggers v-model. Can be one of 'input' (v-model binds a displayed property) or 'select' (v-model binds a selected item).
type, value, pattern, etc... All of the HTML5 input attributes with their respected default values.
nullable-select v1.9.0 Boolean false Whether the select should accept null or not.
preventHide v1.11.0 Boolean false Whether to keep the input open or not, allowing the user to select multiple inputs
mode

New in v1.4.0

Determines the event, that triggers v-model. Can be one of 'input' (default) or 'select'.

For example, if 'input' is chosen - then v-model will update the value each time an input event is fired, setting the input's string.

Same is for 'select' - v-model changes only when something is selected from the list, setting the selected value (string, object or whatever) to its argument.

A proper use-case for it being when one wants to use the component only for selection binding and custom input for text binding:

<vue-simple-suggest v-model="selected" mode="select">
  <input v-model="text">
</vue-simple-suggest>

Emitted Events

Name Arguments Description
input HTML input event An outward projection of the current input's event.
focus HTML focus event An outward projection of the current input's event.
blur HTML focus event An outward projection of the current input's event.
select Selected suggestion Fires on suggestion selection (via a mouse click or enter keypress).
hover Hovered suggestion, target element Fires each time a new suggestion is highlighted (via a cursor movement or keyboard arrows).
suggestion-click Selected suggestion, HTML click event Fires on suggestion element click.
show-list - Fires each time the suggestion list is toggled to be shown.
hide-list - Fires each time the suggestion list is being hidden.
request-start Current input value (query) Fires each time a list function starts executing.
request-done Resulting suggestions list Fires when a list function successfully returns a result and forwards that result as an argument.
request-failed The interrrupting exception Fires if an exception occurs during the execution of a list funciton.

Ref Methods

accessed via $refs.*your ref name here*

Name Arguments Description
showList - Shows the suggestion list. Emits the respected event.
hideList - Hides the suggestion list. Emits the respected event.
getSuggestions query: string Gets and processes suggestions from the list prop. Returns a promise. Emits the requestStart, requestDone and requestFailed events.
research - Debounced getSuggestions on the current input value.
clearSuggestions - Clears the suggestions array.
select suggestion Selects the passed suggestion. Emits the respected event.
hover suggestion Hovers over the passed suggestion. Emits the respected event.
displayProperty suggestion Returns the displayed property of a suggestion.
valueProperty suggestion Returns the value property of a suggestion.
setText v1.9.0 text Reliably sets custom text to the input field.
autocompleteText v1.10.0 suggestion Autocompletes the input text using the suggestion passed as the only argument.

Ref Event Handlers

accessed via $refs.*your ref name here*

You can use these to imitate some of the component's behaviours.

Name Arguments Description
onShowList Invoked when a suggestion list needs to be shown.
showSuggestions Shows suggestion list, refreshes the data if needed.
onInput HTML input event Invoked whenever the input text is changed. Emits the input event.
onFocus HTML focus event Invoked whenever the input comes into focus, emits the focus event.
onBlur HTML focus event Antonym to onFocus.
onAutocomplete - Invoked when the autocomplete keyboard shortcut is pressed. Selects the first suggestion.
onListKeyUp HTML keyup event Invoked on component keyup. Internally used for hiding the list.
onKeyDown HTML keydown event Invoked on component keydown. Internally used for showing the list, updating suggestions and preventing form submit.
moveSelection Invoked when hovered element needs to be changed.
suggestionClick suggestion, HTML click event Invoked on any suggestion click. Can be used to emulate such a click from ouside of the component.

Ref Data

accessed via $refs.*your ref name here*

Name Default Description
selected null Currently selected element.
hovered null Currently hovered element.
suggestions [] Current suggestions list.
textLength 0 Length of the text in the input.
listShown false Is suggestion list shown.
inputElement null Currently used HTMLInputElement.
canSend true Whether the assigned getListFuncion can be executed.
timeoutInstance null The timeout until next getListFunction execution.
text $props.value Current input text.
slotIsComponent false Whether this current custom input is a vue-component.
listIsRequest - Whether the list prop is a function.
input - A ref to the current input (component or vanilla).
hoveredIndex - The current hovered element index.
controlScheme Default Controls The current controls scheme.
isPlainSuggestion false Whether the current suggestions list consists of plain strings (not objects).
isClicking false true if the user currently clicks.
isOverList false true if the user currently hovers over suggestions list.
isInFocus false true if the component is currently in focus.
isTabbed false true if the user pressed tab, while the component is in focus.
isSelectedUpToDate false true if the user hasn't done any inputs since the last selection, so the selection is still relevant.

Slots

Custom input

default slot (optional)

Supports nesting. Input props can be passed to a custom input to avoid their processing by vue-simple-suggest. Defaults to a simple input with props passed to vue-simple-suggest.

Warning: v-model on a custom input IS NOT the same as v-model on vue-simple-suggest!

<!--  Default HTMLInputElement example:  -->
<vue-simple-suggest v-model="model" placeholder="Text here" type="search" pattern="[a-z]+"/>
<!--  Vanilla HTMLInputElement example 1:  -->
<vue-simple-suggest>
  <input pattern="[a-z]+">
</vue-simple-suggest>
<!--  Vanilla HTMLInputElement example 2:  -->
<vue-simple-suggest v-model="model" placeholder="Text here" type="search">
</vue-simple-suggest>
<!--  Vanilla HTMLInputElement example 3 (fully equivalent to the second example):  -->
<vue-simple-suggest v-model="model">
  <input placeholder="Text here" type="search">
</vue-simple-suggest>
<!--  Vanilla HTMLInputElement example 4 (nested):  -->
<vue-simple-suggest v-model="model">
  <div>
    <section>
      <input type="email">
    </section>
  </div>
</vue-simple-suggest>
<!--  Vue component example (also supports nesting):  -->
<vue-simple-suggest v-model="vModelGoesHere">
  <my-custom-input-somponent :value="initialInputValueGoesHere"></my-custom-input-somponent>
</vue-simple-suggest>

Custom input component caveats:

To work with the vue-simple-suggest your custom input component has to follow certain standard behaviours.

Custom input component must (in order to work properly):

  • Emit an input event.
  • Emit focus and blur events.
  • Have a value prop.

Custom input component should (in order to avoid usage limitations):

  • Not stop any event propagations from internal input HTML element.
  • Forward an original event argument with focus and blur events.

If vue-simple-suggest with your custom component doesn't seem to react to outside variable changes - bind both components' v-model to the same variable, like so:

<vue-simple-suggest v-model="model">
  <my-custom-input-somponent v-model="model"></my-custom-input-somponent>
</vue-simple-suggest>
Accessibility on custom input

New in v1.9.0

vue-simple-suggest automatically injects 3 necessary ARIA attributes for the default <input> element and any custom input, as long as your custom input component contains an html <input> element.

These attributes ensure that the autocomplete can be used by users who rely on Screen Readers.

Name Value Description
aria-autocomplete "list" Indicates that the autocomplete behavior of the text input is to suggest a list of possible values in a popup.
aria-controls IDREF of suggestions list IDREF of the popup element that lists suggested values.
aria-activedescendant IDREF of hovered option Enables assistive technologies to know which element the application regards as focused while DOM focus remains on the input element.
Custom suggestion item

suggestion-item slot (optional)

Description

Allows custom html-definitons of the suggestion items in a list. Defaults to <span>{{ displayAttribute(suggestion) }}</span>

Accepts the suggestion object and a query text as a slot-scope attribute values.

<!-- Example (book suggestions): -->
<vue-simple-suggest>
  <div slot="suggestion-item" slot-scope="{ suggestion, query }">
    <div>{{ suggestion.title }} by {{ suggestion.author }}</div>
  </div>
</vue-simple-suggest>

Custom buttons inside of suggestion items

If you want to add some action buttons to the suggetion items, just use the .stop directive modifier to prevent the default suggestion-click:

<!-- Example (editable book suggestion): -->
<vue-simple-suggest>
  <div slot="suggestion-item" slot-scope="{ suggestion, query }">
    <span>{{ suggestion.title }} by {{ suggestion.author }}</span>
    <button @click.stop="remove(suggestion)">remove from list</button>
    <button @click.stop="like(suggestion)">add to favorites</button>
  </div>
</vue-simple-suggest>

In this case, the buttons will ONLY execute the bound method and will not select the suggested item.

Manual autocomplete

If there's a need to autocomplete the suggestion in the input instead of selecting it (like in mobile suggestions of google search), you can use the autocomplete() function in the slot's scope:

<!-- Example: -->
<vue-simple-suggest>
  <div slot="suggestion-item" slot-scope="{ suggestion, autocomplete }">
    <span>{{ suggestion.title }} by {{ suggestion.author }}</span>
    <button @click.stop="autocomplete()">Complete input</button>
  </div>
</vue-simple-suggest>

or in the ref methods:

<template>
  <vue-simple-suggest ref="suggest">
    <div slot="suggestion-item" slot-scope="{ suggestion }">
      <span>{{ suggestion.title }} by {{ suggestion.author }}</span>
      <button @click.stop="onAutocompleteButtonClick(suggestion)">Complete input</button>
    </div>
  </vue-simple-suggest>
</template>

<script>
export default {
  //...
  methods: {
    onAutocompleteButtonClick(suggestion) {
      this.$refs.suggest.autocompleteText(suggestion);
    }
  }
  //...
}
</script>

Ref Data

In cooperation with ref fields this slot can be used to drastically transform the suggestion list behaviour.

One of the simplest examples - highlighting the query text in the results:

<div slot="suggestion-item" slot-scope="scope">
  <span v-html="boldenSuggestion(scope)"></span>
</div>
boldenSuggestion(scope) {
  if (!scope) return scope;

  const { suggestion, query } = scope;

  let result = this.$refs.suggestComponent.displayProperty(suggestion);

  if (!query) return result;

  const texts = query.split(/[\s-_/\\|\.]/gm).filter(t => !!t) || [''];
  return result.replace(new RegExp('(.*?)(' + texts.join('|') + ')(.*?)','gi'), '$1<b>$2</b>$3');
}

Result via Google Books search API:

Custom miscellaneous item slots

misc-item-above and misc-item-below slots (optional)

Allow custom elements to be shown in suggestion list. These elements never dissapear from the list, neither can they be selected nor hovered on.

They can be used for decoration, loaders, error messages and etc.

These slots don't have defaults, so they are not shown until defined.

Accept the suggestions array and a query text as a slot-scope attribute values.

<!-- Examples: -->
<vue-simple-suggest>
  <template slot="misc-item-above" slot-scope="{ suggestions, query }">
    <div class="misc-item">
      <span>You're searching for {{ query }}.</span>
    </div>
    <div class="misc-item">
      <span>{{ suggestions.length }} suggestions are shown...</span>
    </div>
  </template>

  <div slot="misc-item-below" slot-scope="{ suggestions }" v-if="isLoading" class="misc-item">
    <span>Loading...</span>
  </div>
</vue-simple-suggest>

These slots can also be used to handle empty results, like this:

<!-- Main slot template -->
<template slot="misc-item-above" slot-scope="{ suggestions, query }">
  <div class="misc-item">
    <span>You're searching for '{{ query }}'.</span>
  </div>

  <!-- Sub-template if have any suggestions -->
  <template v-if="suggestions.length > 0">
    <div class="misc-item">
      <span>{{ suggestions.length }} suggestions are shown...</span>
    </div>
    <hr>
  </template>

  <!-- Show "No result" otherwise, if not loading new ones -->
  <div class="misc-item" v-else-if="!loading">
    <span>No results</span>
  </div>
</template>

Contributors

Thanks goes to these wonderful people (emoji key):


Alexey

😇

Karen

😐

Simeon Kerkola

💻 📖 🤔

Roberson Costa

💻 📖 🤔

Rosdi Kasim

📖

antoinematyja

🤔

Matthias Martin

🐛

Rob Brain

🐛 🐛

MrWook

🐛

nattam

🤔

Petr

🐛

RMFogarty

💬

Brian Monsales

💬

Mila76

🐛

Andriy Löfberg

💬 🤔 💻

Bruno Monteiro

🤔

hannesaasamets

🐛

Jimmy

🐛

Will Plaehn

💻 🤔 📖

lauri911

🐛

Alex Hyriavets

🐛

Behnood Khani

🐛

Hay Kranen

📖

shrpne

🐛 💻 🤔

Peta Dragos-Andrei

🐛

shoito

📖

yamagen0915

🐛 💻

This project follows the all-contributors specification. Contributions of any kind are welcome!

vue-simple-suggest's People

Contributors

allcontributors[bot] avatar dependabot-preview[bot] avatar dependabot[bot] avatar hay avatar jesseschutt avatar kaskar2008 avatar mike-13 avatar raiondesu avatar rosdi avatar shoito avatar shrpne avatar simeonkerkola avatar tbl0605 avatar xlcrr avatar yamagen0915 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue-simple-suggest's Issues

Select item causes form submit event

I'm submitting a ...

  • bug report
  • feature request
  • support request

What is the current behavior?

Selecting list item by Enter causes submit event on form submit button.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

  1. On the demo start typing some text in the field
  2. Select item by Enter
  3. If you have below submit button, it causes submit event.

What is the expected behavior?

It not causes form submit event.

How are you importing Vue-simple-suggest?

  • ESNext (original code, single-file .vue component, css included) (import VueSimpleSuggest from 'vue-simple-suggest/lib')
  • ES6 (import VueSimpleSuggest from 'vue-simple-suggest')
  • ES7 and above (import VueSimpleSuggest from 'vue-simple-suggest/dist/es7')
  • Bundled version (import VueSimpleSuggest from 'vue-simple-suggest')
  • CommonJS (const VueSimpleSuggest = require('vue-simple-suggest'))
  • UMD Component (<script type="text/javascript" src="https://unpkg.com/vue-simple-suggest"></script>)

Please tell us about your environment:

  • Vue.js Version: 2.5.16
  • Vue-simple-suggest version: 1.7.2
  • Browser: Chrome 67
  • Language: [all]
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)

I had tried add event.stopPropagation() to onListkeyUp method, but with no success.

 if (hasKeyCode([select, hideList], e)) {
        e.preventDefault()
        e.stopPropagation()
        if (this.listShown) {
          if (hasKeyCode(select, e) && this.hovered) {
            this.select(this.hovered)
          }
          this.hideList()
        } else if (hasKeyCode(select, e)) {
          this.research()
        }
      }

Using list of objects from REST

Wired thing happening, my rest request return list of objects and not list with strings (etc).

[
   {
     "HighlightedName":"some val",
     "key2":"some val"
   },
   {
     "HighlightedName":"some val",
     "key2":"some val"
   }
]

No in HTML i can see this image
But there is no autosuggest dropdown or whatever.

Any idea?

IE 11 bug

I'm submitting a ...

  • bug report
  • feature request
  • support request

What is the current behavior?

I use it in IE11 and get the error: Syntax error: ...const a=t=>t.some(t=>t===e.keyCode).
I discovered it and found that this piece of code is in https://github.com/KazanExpress/vue-simple-suggest/blob/master/lib/misc.js and babel-loader cannot transpile it into ES5.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

  • import this plugin as CJS: vue-simple-suggest/dist/cjs
  • use it on some page
  • open this page in IE11
  • get syntax error

What is the expected behavior?

I expect that this plugin will be work correct in IE11

How are you importing Vue-simple-suggest?

  • ESNext (original code, single-file .vue component, css included) (import VueSimpleSuggest from 'vue-simple-suggest/lib')
  • ES6 (import VueSimpleSuggest from 'vue-simple-suggest')
  • ES7 and above (import VueSimpleSuggest from 'vue-simple-suggest/dist/es7')
  • Bundled version (import VueSimpleSuggest from 'vue-simple-suggest')
  • CommonJS (const VueSimpleSuggest = require('vue-simple-suggest'))
  • UMD Component (<script type="text/javascript" src="https://unpkg.com/vue-simple-suggest"></script>)

Please tell us about your environment:

  • Vue.js Version: 2.9.3
  • Vue-simple-suggest version: 1.8.2
  • Browser: [all]
  • Language: [ES6/7 | ES5]

Get rid of Object.assign and awaits?

I'm submitting a ...

  • bug report
  • feature request
  • support request

What is the current behavior?

Currently, there're Object.assign and awaits in the code. First requires polyfills in IE, second require special transpilers for older browsers.

What is the expected behavior?

A dependences-free lib. (Ideally)

Possible solutions

  1. Replace awaits with promises
  2. Replace Object.assign with Object.keys
  3. Provide different versions for different ES standads (es5, es6, esnext and a browser-link).

UglifyJS error when building for `production`

I'm submitting a ...

  • bug report
  • feature request
  • support request

What is the current behavior?

With my basic laravel-mix-based webpack.config I use uglify to build the application for production. All other non-uglify build methods work without a hitch. However, now that I've added vue-simple-suggest to the application, when running yarn run production (which tries to uglify) I receive the following:

/js/main.js from UglifyJs
Invalid assignment [./node_modules/vue-simple-suggest/dist/es6.js:15,0][/js/main.js:229346,39]

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

yarn run production

What is the expected behavior?

Build and uglify/minify without throwing an error.

How are you importing Vue-simple-suggest?

  • ESNext (original code, single-file .vue component, css included) (import VueSimpleSuggest from 'vue-simple-suggest/lib')
  • ES6 (import VueSimpleSuggest from 'vue-simple-suggest')
  • ES7 and above (import VueSimpleSuggest from 'vue-simple-suggest/dist/es7')
  • Bundled version (import VueSimpleSuggest from 'vue-simple-suggest')
  • CommonJS (const VueSimpleSuggest = require('vue-simple-suggest'))
  • UMD Component (<script type="text/javascript" src="https://unpkg.com/vue-simple-suggest"></script>)

What is the motivation / use case for changing the behavior?

I'd like to be able to minify without issue. I've upgraded all relevant packages, to no avail.

Please tell us about your environment:

  • Vue.js Version: 3.0.0-beta.15
  • Vue-simple-suggest version: 1.8.2
  • Browser: [N/A]
  • Language: [ES6/7]
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)

When empty list is returned by query, then "no results" is not handled properly.

I'm submitting a ...

  • bug report
  • feature request
  • support request

What is the current behavior?

When empty list is returned by query, then "not found" is not handled properly.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

  1. open https://kazanexpress.github.io/vue-simple-suggest/
  2. type "adfasdfasdf"
  3. you will see a line appearing below input (empty dropdown is show).

What is the expected behavior?

One way to handle it:

Create a special slot "no-results" - then user can handle it (pass "query" to this slot as well)

At moment you have this layout:

  1. miscItemAbove
  2. suggestItems
    
  3. miscItemBelow

...and question is how to hande "no-results" layout.
I prefer this, because header and footer are usually about results, no-result is handled differently:
With results:

  1. miscItemAbove
  2. suggestItems
    
  3. miscItemBelow
    Without results:
  4. no-results slot

If "no-results" slot is not defined by user, then hide dropdown completly.
For example, for hidding dropdown use
computed:
hasNoResultsSlot () {
return !!this.$scopedSlots['no-results'];
}

PS. Please use same convention for slot names - camelCase or kebab-case, not mixed.
Its hard to remember, was it miscItem-above or miscItem-Above or miscItem-Above or misc-ItemAbove. (Maybe rename them: results-header and results-footer)

Auto-install, if included via script tag

I'm submitting a ...

  • bug report
  • feature request
  • support request

What is the current behavior?

The component needs to be defined explicitly, when included via <script>. This makes clean umd build impossible to use in the browser.

What is the expected behavior?

The component would register itself in the Vue instance, if it's presented in global scope.

Mode 'select' showing [object Object] when clicking the suggestion.

I'm submitting a ...

  • bug report
  • feature request
  • support request

It works fine if I don't specify the v-model, but how to get the selected value without v-model?
Please help...

2018-08-22_14-16-19

This is my code

<template>
	<div>
		<vue-simple-suggest
			class="m-5"
			ref="suggestComponent"
			v-model="chosen"
			mode="select"
			display-attribute=name
			value-attribute=id
			:debounce=500
			:list="customerList"
			:filter-by-query="true">
		</vue-simple-suggest>
	</div>
</template>

data() {
	return {
		chosen: '',
		customerList: [
			{
				id: 1,
				name: 'John',
			},
			{
				id: 2,
				name: 'Jane',
			},
			{
				id: 3,
				name: 'July',
			},
		],
	}
},

This is how I importing Vue-simple-suggest

in the main.js

import VueSimpleSuggest from 'vue-simple-suggest'
Vue.component('vue-simple-suggest', VueSimpleSuggest)

I use

  • Vue.js Version: 2.5.17
  • Vue-simple-suggest version: 1.8.1
  • Browser: Chrome Version 68.0.3440.106 (Official Build) (64-bit)

Support for suggestions grouping

Does this component support grouping (similar to optgroup)?
I didn't see it in the doc.

The doc tells us about 'custom item', but I need to customize one level up (group of items)

Autocomplete using Controls always selects first suggestion

I'm submitting a ...

  • bug report
  • feature request
  • support request

What is the current behavior?

Using Controls the first suggestion is always returned on autocomplete

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

In the example - https://kazanexpress.github.io/vue-simple-suggest/
Search -> arrow down to select a suggest (not the first) -> Ctrl/Shift Enter to autocomplete. The first suggestion will be returned.

What is the expected behavior?

The correct suggestion returned.

How are you importing Vue-simple-suggest?

  • ESNext (original code, single-file .vue component, css included) (import VueSimpleSuggest from 'vue-simple-suggest/lib')
  • ES6 (import VueSimpleSuggest from 'vue-simple-suggest')
  • ES7 and above (import VueSimpleSuggest from 'vue-simple-suggest/dist/es7')
  • Bundled version (import VueSimpleSuggest from 'vue-simple-suggest')
  • CommonJS (const VueSimpleSuggest = require('vue-simple-suggest'))
  • UMD Component (<script type="text/javascript" src="https://unpkg.com/vue-simple-suggest"></script>)

What is the motivation / use case for changing the behavior?

Please tell us about your environment:

  • Vue.js Version: 2.5.16
  • Vue-simple-suggest version: 1.7.1
  • Browser: [Chrome 66]
  • Language: [ES6/7]
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)

"select" event is sent when clearing input

I'm submitting a ...

  • bug report

What is the current behavior?

If you highlight the content of the input and hit "backspace" to clear the input then a "select" event is fired with a null payload. I would assume that select would be called only if you actually selected something. So i'm not sure why select is being called here. Entering backspace to clear the input is just typing so it shouldn't be selecting anything.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

You can view a video here: https://www.useloom.com/share/2f336be5796d4fac82fb15996b64b7f4

  1. Go to the demo and search for "Helicopter"
  2. Select "Helicopter"
  3. Press Ctrl+A
  4. Press Backspace
  5. The a "select" event will be fired.

Oddly if you're typing and "ctrl+a" and then "backspace" a select event won't fire. It's only fired if you do so after a mouse click from what I can tell.

What is the expected behavior?

Select should not fired on a backspace. It says in the docs that select is only fired on "a mouse click or enter keypress".

How are you importing Vue-simple-suggest?

  • ES6 (import VueSimpleSuggest from 'vue-simple-suggest')
    </script>`)

What is the motivation / use case for changing the behavior?

It's a bug

Please tell us about your environment:

  • Vue.js Version: 2.5.17
  • Vue-simple-suggest version: 1.8.2
  • Browser: Chrome Windows
  • Language: ES6

Can't select items with arrow up/down keys when suggestion list has scrolled content

I'm submitting a ...

  • bug report
  • feature request
  • support request

What is the current behavior?

I have a large number of suggestions and have set a max-height with overflow:hidden to the suggestions overlay. So at the moment only 5 suggestions are shown but with the mousepad the user can scroll the overlay list and select any option.

The user can't use the arrow up/down keys though to select items not in view.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

I used your demo example on the site. I added additional data to the list. I set a max-height of 100px and set overflow:hidden on the "suggestions" element. This creates scrolled content in the overlay.

Now type a letter to see the overlay with results. Start pressing the down arrow and notice the list does not scroll and items not currently in view remain hidden.

What is the expected behavior?

I'd expect the list to scroll when hovering/focusing on an item not visible in the list with the arrow up/down keys.

How are you importing Vue-simple-suggest?

  • ESNext (original code, single-file .vue component, css included) (import VueSimpleSuggest from 'vue-simple-suggest/lib')
  • ES6 (import VueSimpleSuggest from 'vue-simple-suggest')
  • ES7 and above (import VueSimpleSuggest from 'vue-simple-suggest/dist/es7')
  • Bundled version (import VueSimpleSuggest from 'vue-simple-suggest')
  • CommonJS (const VueSimpleSuggest = require('vue-simple-suggest'))
  • UMD Component (<script type="text/javascript" src="https://unpkg.com/vue-simple-suggest"></script>)

What is the motivation / use case for changing the behavior?

Accessibility and allowing folks to use standard/common keyboard commands to interact with an auto-complete component.

Please tell us about your environment:

  • Vue.js Version: 2.5.16
  • Nuxt 2.0
  • Vue-simple-suggest version: 1.8.2
  • Browser: [ Chrome latest | Firefox latest | IE 11 | Safari latest | Mobile Chrome | iPhone 6+ ]
  • Language: ES6/7

Main input events take object as an argument regardless of the list structure

I'm submitting a ...

  • bug report
  • feature request
  • support request

What is the current behavior?

select, input and hover events take an object as an item argument, even if the list itself didn't contain objects.

Example:

// Input list:
[ 'apple', 'banana', 'cat' ]

// `select` event's argument if 'banana' is selected
{
  title: 'banana',
  id: 1
}

What is the expected behavior?

The prescribed events should adapt to the current list input whatever the internal converted structure is.

For example:

// Input list:
[ 'apple', 'banana', 'cat' ]

// `select` event's argument if 'banana' is selected
'banana'

What is the motivation / use case for changing the behavior?

Usability.

IE 11 Support?

I'm submitting a ...

  • bug report
  • feature request
  • support request

What is the current behavior?

Loading the component in IE 11 results in a Syntax Error, caused by the arrow functions in the ES6.js file. I can't tell if this component is IE 11 compatible or not, if it is, am I missing an option or build step to get it back to ES2015 compliant.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

What is the expected behavior?

How are you importing Vue-simple-suggest?

  • ESNext (original code, single-file .vue component, css included) (import VueSimpleSuggest from 'vue-simple-suggest/lib')
  • ES6 (import VueSimpleSuggest from 'vue-simple-suggest')
  • ES7 and above (import VueSimpleSuggest from 'vue-simple-suggest/dist/es7')
  • Bundled version (import VueSimpleSuggest from 'vue-simple-suggest')
  • CommonJS (const VueSimpleSuggest = require('vue-simple-suggest'))
  • UMD Component (<script type="text/javascript" src="https://unpkg.com/vue-simple-suggest"></script>)

What is the motivation / use case for changing the behavior?

We have an application that must support IE 11 and hope to use this component.

Please tell us about your environment:

  • Vue.js Version: 2.5.16
  • Vue-simple-suggest version: 1.8.0
  • Browser: IE 11
  • Language: TypeScript 2.9.2
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)

Improve "bolden" example - single character "b"

I'm submitting a ...

  • bug report
  • feature request
  • support request

What is the current behavior?

When the single letter "b" is entered and a suggestion list is populated, Multiple <b> tags are created. This appears to be because of the multiple-passes approach used to handle different capitalizations. See screenshot.

image

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

  1. https://kazanexpress.github.io/vue-simple-suggest/
  2. Type b plus two additional letters to get suggestions list to appear (e.g. "bab")
  3. Delete characters until only "b" is in the input box

What is the expected behavior?

Correct highlighting!

What is the motivation / use case for changing the behavior?

For use cases where suggestions are given for a single character, this is a serious issue vs. just an edge case as in the scenario above.

Please tell us about your environment:

N/A

Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)

Suggesting to do it in one pass to avoid this issue. We can also make the function more understandable and avoid enumerating each capitalization case by using a case-insensitive regex.

Here is an example function that mitigates the issue. texts is also modified from the original to split on commas. Submitting this as an issue vs. a PR because I'm not sure if it covers all of your edge cases.

boldenSuggestion({ suggestion, query }) {
  let result = this.$refs.suggestComponent.displayProperty(suggestion);
  const texts = query.split(/[\s-_/\\|\.\,]/gm).filter(t => !!t) || [''];
  return result.replace(new RegExp('(.*?)(' + texts.join('|') + ')(.*?)','gi'), '$1<b>$2</b>$3');
},

Suggestion item click is not working

I'm submitting a ...

  • bug report
  • feature request
  • support request

What is the current behavior?

The hiding of the list is much faster then the click event, so it can't be done in the way it expected to work.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

<vue-suggest>
   <div slot="suggestion-item" slot-scope="{ suggestion }" @click="/* not working */">
      <span @click="/* not working */">{{ suggestion.title }}</span>
   </div>
</vue-suggest>

Focus event seems not to be registering in Safari or Firefox

I'm submitting a ...

  • bug report
  • feature request
  • support request

What is the current behavior?

Background:
I'm using several simple-suggest components in one form. The first is a list of shipper names, the second a list of addresses. The second's list is generated based on the input from the first.

When the second input comes into focus, it's supposed to trigger a function that sends a POST request to get back a list of locations based on the name selected in the previous input. Unfortunately, the expected behavior is only happening in Chrome.

I initially tried to use v-on:select="function" on the first input, but found that it was only sending what the user had typed, not the actual selection; so I decided to make it @Focus="function" on the second, ensuring that the selection registered prior to the request being sent.

This works like a charm in Chrome, but nothing happens in Safari or Firefox (although the "focus" class is appearing on the div)-- it appears that the browser doesn't register a focus event being emitted. A similar function works on a regular <textarea> in all browsers, so it seems it's vue-simple-suggest causing the problem.

I have no idea how to go about fixing this, or figuring out why it's happening.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

Here's a demo that shows the issue (I've removed the API calls and the rest of the interface for security/eas of use purposes):
https://codesandbox.io/s/k5y9pnm3v

What is the expected behavior?

When the second input comes into focus, it's supposed to trigger a function that sends a POST request to get back a list of locations based on the name selected in the previous input.

How are you importing Vue-simple-suggest?

  • ESNext (original code, single-file .vue component, css included) (import VueSimpleSuggest from 'vue-simple-suggest/lib')
  • ES6 (import VueSimpleSuggest from 'vue-simple-suggest')
  • ES7 and above (import VueSimpleSuggest from 'vue-simple-suggest/dist/es7')
  • Bundled version (import VueSimpleSuggest from 'vue-simple-suggest')
  • CommonJS (const VueSimpleSuggest = require('vue-simple-suggest'))
  • UMD Component (<script type="text/javascript" src="https://unpkg.com/vue-simple-suggest"></script>)

Please tell us about your environment:

  • Vue.js Version: 2.5.0
  • Vue-simple-suggest version: 1.7.0
  • Browser: Firefox 59.0.2 | Safari 11.1.1 ]
  • Language: [ ES6/7 | ES5 ]
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)

Clear currently selected item.

I'm submitting a ...

  • bug report
  • feature request
  • support request

What is the current behavior?

I am sorry if this is covered anywhere, but I have been looking for quite sometime to find a way to clear the search text after selecting an item.

this would be great for different use cases, for example if a user search for multiple items in a list, I would like to clear the selected item when they click it and prompt them to search for another item (I would add the selected item on a different list, so no need for multiple select in the input).

What is the expected behavior?

Be able to clear search entry, by either have a button to clear search text on be able to clear it via events.

What is the motivation / use case for changing the behavior?

I am using auto-suggest to allow users to select multiple cities/location, each time they choose one it will be added and they will be prompted to search for another location.

Please tell us about your environment:

  • Vue.js Version: 2.5.0
  • Vue-simple-suggest version: 1.7.0
  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
  • Language: [all | TypeScript X.X | ES6/7 | ES5 | Dart]

Reset input after validation

Hi everybody,

I'm submitting a ...

  • bug report
  • feature request
  • support request

** Configuration **

<vue-simple-suggest ref="suggestComponent"
                          v-model="selected" mode="select"
                          :max-suggestions="10"
                          :min-length="1"
                          :debounce="200"
                          :controls="{
                            selectionUp: [38, 33],
                            selectionDown: [40, 34],
                            select: [13, 36],
                            hideList: [27, 35]
                          }"
                          :list="simpleSuggestionList"
                          :placeholder="placeholder"
                          :display-attribute="'value'"
                          :value-attribute="'value'"
                          @select="validAutocomplete"
                          @hover="onSuggestHover"
                          @request-start="onRequestStart"
                          @request-done="onRequestDone">
        <input class="inputText" v-model="text" :display-attribute="'count'" />
        ....
</vue-simple-suggest>

What is the current behavior?

I'm using the select mode with a min-length at 1.
When i select an item (mouse or keyboard) then validate the input, i need to reset the input and blur. How can i do this ?

I try to reset the v-model text like this into validAutocomplete method.

validAutocomplete(data) {
        if (data) {
          this.$emit('selected', data.value);
          this.text = "";
          this.selected = "";

          // Unfocus all inputText elements
          this.$nextTick(function() {
            Array.prototype.forEach.call(document.getElementsByClassName('inputText'), function(el) {
              el.blur();
            });
          });
        }
 }

When i do this, input has been reset and blur. But when i write again in the input, autocomplete not working and get the old autocomplete list (like a cache system) and call not working.

How are you importing Vue-simple-suggest?

  • ESNext (original code, single-file .vue component, css included) (import VueSimpleSuggest from 'vue-simple-suggest/lib')
  • ES6 (import VueSimpleSuggest from 'vue-simple-suggest')
  • ES7 and above (import VueSimpleSuggest from 'vue-simple-suggest/dist/es7')
  • Bundled version (import VueSimpleSuggest from 'vue-simple-suggest')
  • CommonJS (const VueSimpleSuggest = require('vue-simple-suggest'))
  • UMD Component (<script type="text/javascript" src="https://unpkg.com/vue-simple-suggest"></script>)

Please tell us about your environment:

  • Vue.js Version: 2.5.0
  • NuxtJs Version : 1.4.0
  • Vue-simple-suggest version: 1.7.2
  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
  • Language: [all | TypeScript X.X | ES6/7 | ES5 | Dart]

Thanks a lot for your help.
Best regards :)

Maybe do not hide the list, if minLength === 0?

I'm submitting a ...

  • bug report?
  • feature request
  • support request

What is the current behavior?

Currently, if the text length gets to 0, with min-length prop also being 0, the suggestion list will hide, even if it contains something (a default list, for example).
It will become visible again after clicking on input, though.

What is the expected behavior?

I expect some way to keep the list showed even with the absence of text.

What is the motivation / use case for changing the behavior?

It seems much more convenient to me to still show the list, if the minlength is 0 and there are some suggestions around.

Autocomplete from the most suitable suggestion element?

I'm submitting a ...

  • bug report
  • feature request
  • support request

What is the expected behavior?

When the suggestions list is not empty - get the rest of the text from the element, that complete the most.

What is the motivation / use case for changing the behavior?

In some cases this type of autocompletion is the most convenient (for example, if the component being used as a search box for some results)

Add simple usage examples

Current documentation lacks full simple usage examples.
Also need to draw more attention to the main source of data for component - the list prop.

`blur` and `focus` events are not working with custom input

I'm submitting a ...

  • bug report
  • feature request
  • support request

What is the current behavior?

The blur event never occurs if a custom input component is used in the slot.
Literally every other event does, except for the blur.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

Just pass any custom input component into the default slot and oped devtools->events. You'll see that with any interaction the component emits NONE.

What is the expected behavior?

The events should work in any circumstance.

Support for <textarea>

I'm submitting a ...

  • feature request

I use vue-simple-suggest with a Dadate.
Addresses are usually quite long.
And the input field does not always fit the entire address.
Especially on mobile devices.
It would be great to add a setting for
field type input or textarea.

Example:

suggests

Hovered with arrow Up / down

I'm submitting a ...

  • bug report
  • feature request
  • support request

Hi guys, thanks a lot for your work.
I found a problem about hovered only with arrow up and down.
But maybe i do something wrong about my configuration ?

<vue-simple-suggest ref="suggestComponent"
                          v-model="selected" mode="select"
                          :max-suggestions="10"
                          :min-length="1"
                          :debounce="200"
                          :controls="{
                            selectionUp: [38, 33],
                            selectionDown: [40, 34],
                            select: [13, 36],
                            hideList: [27, 35]
                          }"
                          :list="simpleSuggestionList"
                          :placeholder="placeholder"
                          :display-attribute="'value'"
                          @select="validAutocomplete"
                          @hover="onSuggestHover"
                          @request-start="onRequestStart"
                          @request-done="onRequestDone">
        <input class="inputText" v-model="text" :placeholder="placeholder" @focus="isFocus = true" @blur="isFocus = false" :display-attribute="'count'" />

        <template slot="misc-item-above" slot-scope="{ suggestions, query }">
          <!-- Show "No result" otherwise, if not loading new ones -->
          <div class="misc-item" v-if="suggestions.length === 0 && !loading">
            <p><span>No results</span> - Bla bla bla ...</p>
          </div>
        </template>

        <div slot="suggestion-item" slot-scope="scope">
          <div class="text">
            <span>{{ scope.suggestion.value }}</span>
          </div>
          <div class="count">
            <span>{{ scope.suggestion.count }}</span>
          </div>
        </div>

        <div class="misc-item" slot="misc-item-below" slot-scope="{ suggestions }" v-if="loading">
          <span>Loading ...</span>
        </div>
      </vue-simple-suggest>
onSuggestHover(suggestion) {
        console.log('suggestion = ', suggestion.value);       
}

The problem :
When i use mouse to hover on suggestion, there is no bug.
When i use nav arrow down, the value on the first and second item works but not the others. It seems to be block at second items but not with the mouse.

Thanks for your help.
Regards,

Custom Input input event is not handled

I'm submitting a ...

  • bug report
  • feature request
  • support request

What is the current behavior?

Custom Input input.stop="onInput" does not trigger the suggestions list to be opened. The native input's event propagation has to be limited within the Custom Input component to avoid two input events surfacing. When the custom event emits its own input event, the suggestions list is not opened.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

Inside Custom Input specifying @input.stop="onInput" for the native input and then handling it on the Custom Input level as following

onInput (e) {
  this.$emit('input', e.target.value)
  console.log('input', e)
},

What is the expected behavior?

The Custom Input's input event should suffice for the suggestions to appear

What is the motivation / use case for changing the behavior?

This behavior the Custom Input can not be changed and there is no obvious reason to do it either.

Please tell us about your environment:

  • Version: 1.6.0
  • Browser: Chrome 66
  • Language: ES6/7

having trouble implementing the "boldenSuggestion" example

I'm submitting a ...

  • bug report
  • feature request
  • support request / documentation request

What is the current behavior?

I am trying to implement the "boldenSuggestion" example from the docs, but I'm having issues with this.$refs.suggestComponent not being defined:

Error in render: "TypeError: this.$refs.suggestComponent is undefined"

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

Below is the code where I added the "suggestion-item" slot and the boldenSuggestion() js code to the "Simple example" from the docs:

<!-- Some component.vue -->
<template>
  <div>
    <vue-simple-suggest v-model="chosen" :list="simpleSuggestionList" :filter-by-query="true">
      <div slot="suggestion-item" slot-scope="scope">
        <span v-html="boldenSuggestion(scope)"></span>
      </div>
    </vue-simple-suggest>

    <br>

    <p>Chosen element: {{ chosen }}</p>
  </div>
</template>

<script>
import VueSimpleSuggest from 'vue-simple-suggest'
import 'vue-simple-suggest/dist/styles.css' // Optional CSS

export default {
  components: {
    VueSimpleSuggest
  },
  data() {
    return {
      chosen: ''
    }
  },
  methods: {
    simpleSuggestionList() {
      return [
        'Vue.js',
        'React.js',
        'Angular.js'
      ]
    },
    boldenSuggestion(scope) {
      if (!scope) return scope;
      const { suggestion, query } = scope;
      let result = this.$refs.suggestComponent.displayProperty(suggestion);
      if (!query) return result;
      const texts = query.split(/[\s-_/\\|\.]/gm).filter(t => !!t) || [''];
      return result.replace(new RegExp('(.*?)(' + texts.join('|') + ')(.*?)', 'gi'), '$1<b>$2</b>$3');
    }

  }
}
</script>

When typining the input box, no suggestions are shown and the following JS error is thrown in Firefox:

  Error in render: "TypeError: this.$refs.suggestComponent is undefined"

and Chrome:

TypeError: Cannot read property 'displayProperty' of undefined

What is the expected behavior?

To see the suggestion list with the query highlighted

How are you importing Vue-simple-suggest?

  • ESNext (original code, single-file .vue component, css included) (import VueSimpleSuggest from 'vue-simple-suggest/lib')
  • ES6 (import VueSimpleSuggest from 'vue-simple-suggest')
  • ES7 and above (import VueSimpleSuggest from 'vue-simple-suggest/dist/es7')
  • Bundled version (import VueSimpleSuggest from 'vue-simple-suggest')
  • CommonJS (const VueSimpleSuggest = require('vue-simple-suggest'))
  • UMD Component (<script type="text/javascript" src="https://unpkg.com/vue-simple-suggest"></script>)

Please tell us about your environment:

  • Vue.js Version: 3.0.1
  • Vue-simple-suggest version: 1.8.2
  • Browser: [all | Chrome 68 | Firefox 62]
  • Language: [all | ES6/7 | ES5 ]
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)

How to use filter-by-query and how to pipe the text before it reaches vue-simple-suggest?

I'm submitting a ...

  • bug report
  • feature request
  • support request

Given the simple example below:

<!-- Some component.vue -->
<template>
  <div>
    <vue-simple-suggest v-model="chosen" :list="simpleSuggestionList" :filter-by-query="true">
      <input type="text" v-model="chosen">
    </vue-simple-suggest>

    <br>

    <p>Chosen element: {{ chosen }}</p>
    <p v-on:click="clickme">click me</p>
  </div>
</template>

<script>
import VueSimpleSuggest from 'vue-simple-suggest'
import 'vue-simple-suggest/dist/styles.css' // Optional CSS

export default {
  components: {
    VueSimpleSuggest
  },
  data() {
    return {
      chosen: ''
    }
  },
  methods: {
    simpleSuggestionList() {
      return [
        'Vue.js',
        'React.js',
        'Angular.js'
      ]
    },
    clickme() {
      this.chosen = "js";
    }
  }
}
</script>

Question 1:

  • Type "vue" in the input box, the dropdown shows "Vue.js"
  • Click on "click me", it sets the value of the "chosen" input box to "js"
  • Then click on the input box. Note that the dropdown still shows "Vue.js" instead of the three options that contains "js". You have to actually type in the input box in order for the dropdown to update.

So... Is there a way to tell VueSimpleSuggest that the value of "chosen" has been updated, so when the user clicks the input box the correct options are displayed?

Question 2:
If you type "js" (including the quotes) into the "chosen" input box, there are no results. Is there a way intercept the query and strip the quotes before VueSimpleSuggest processes it? Note: I don't want to change the value of "chosen" , just massage it before VueSimpleSuggest looks for it in simpleSuggestionList

Thank you for any help you can provide!

How are you importing Vue-simple-suggest?

  • ESNext (original code, single-file .vue component, css included) (import VueSimpleSuggest from 'vue-simple-suggest/lib')
  • ES6 (import VueSimpleSuggest from 'vue-simple-suggest')
  • ES7 and above (import VueSimpleSuggest from 'vue-simple-suggest/dist/es7')
  • Bundled version (import VueSimpleSuggest from 'vue-simple-suggest')
  • CommonJS (const VueSimpleSuggest = require('vue-simple-suggest'))
  • UMD Component (<script type="text/javascript" src="https://unpkg.com/vue-simple-suggest"></script>)

Please tell us about your environment:

  • Vue.js Version: 3.0.1
  • Vue-simple-suggest version: 1.8.2
  • Browser: [all | Chrome 68 | Firefox 62]
  • Language: [all | ES6/7 | ES5 ]

Provide a more intuitive way of keeping the list shown after suggestion click

I'm submitting a ...

  • bug report
  • feature request
  • support request

What is the current behavior?

After clicking on a suggestion item the suggestions list becomes hidden (here)

What is the motivation / use case for changing the behavior?

After clicking on a suggestion item I want the suggestions list to optionally keep showing.

Scoped slots detection is partially broken in functional components

I'm submitting a ...

  • bug report
  • feature request
  • support request

What is the current behavior?

If only one slot is defined at-a-time - it will not be shown.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

  1. Create a sample environment for vue-simple-suggest
  2. Create a getList function that fails to deliver a response consecutively after some successful trials
  3. Declare a misc-item-below slot with v-if that shows it upon request loading.
  4. Open the example and see for yourself.
    4.1. If the returned result is valid - the slot is successfully shown. Also, it is shown on a first-in-a-row invalid result.
    4.2. Upon the second failed attempt, that loading slot is not displayed anymore.

What is the expected behavior?

It must show the slots whenever they are defined on the instance.

Fixing suggestions

Maybe rework the slot-checking mechanism?

Execute search on ArrowDown if no suggestions provided?

I'm submitting a ...

  • bug report
  • feature request
  • support request

What is the current behavior?

Currently, if there's no suggestions (suggestion list is empty), the list will be shown only after pressing Enter (executing list/getSuggestions function). The intuitive arrow down (show-list-key) will do nothing in this context.

What is the expected behavior?

When there're no suggestions, the pressing of arrow down (show-list-key) would also work the same way as pressing the Enter (search-key), but only in this specific context. In all other contexts, the arrow down (show-list-key) would only show the list of suggestions.

Such a behaviour currently would only be achieved only by including the arrow down (show-list-key) in same control section where the Enter (search-key) is now. Which is not convenient at all.

What is the motivation / use case for changing the behavior?

In the case of showing the suggestions when there's none, it seems convenient to me to search for them.

Question: Custom filter function

I'm newest at vue and trying to implement your autocomplete.
Could you please to provide the example of 'customFilterFunction' that was included to docs at TLDR section:

<vue-simple-suggest ... :filter="customFilterFunction" ... ></vue-simple-suggest>

and then I read:

filter | Function | - | A custom function for filtering the suggestion results that accepts a single item and a query to filter by as its 2 arguments. Used only if filter-by-query is set to true.

but still can't understand, whats data is this function retuns or changes?

Cannot read property 'suggestion' of undefined

I'm submitting a ...

  • bug report
  • support request
  • feature request

What is the current behavior?

I don't understand how to use custom suggestion items. I got this error :
Cannot read property 'suggestion' of undefined

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

Here it is my getList() method

methods: {
      getList(inputValue) {
        let jsonList = this.$store.getters['places/getPlacesN1']
        let arrayList = []
        jsonList.forEach( el => {
          arrayList.push({
            id: el.fields.googlePlaceId.fr,
            name: el.fields.name.fr
          })
        })
        return arrayList
      }
    }

In my template

<vue-simple-suggest
      v-model="query"
      :list="getList"
      placeholder="Essayer 'Planétarium'"
      type="search"
      ref="suggestComponent"
      mode="input"
      :filter-by-query="false"
      >

      <div slot="suggestion-item" slot-scope="scope" :title="scope.suggestion.name">
          <div class="text">
            <span v-html="boldenSuggestion(scope)"></span>
          </div>
      </div>
</vue-simple-suggest>

What is the expected behavior?

I want to display a specific list reached from json in suggestions items. However, I have 'undefined' written in it.

What is the motivation / use case for changing the behavior?

Please tell us about your environment:

  • Version: 2.0.0-beta.X
  • Browser: Chrome 66
  • Language: ES6

List is not shown immideately if min-length is 0

I'm submitting a ...

  • bug report
  • feature request
  • support request

What is the current behavior?

Currently, if min-length is 0 - the list won't show on click/focus.

What is the expected behavior?

I expect it to show on whatever min-length is set.

IE 11 compatibility

I'm submitting a ...

  • bug report
  • feature request
  • support request

What is the current behavior?

Unfortunately, I need to support IE 11.

I'm trying to get the sample app to work in Vue 3.0.1. I've read the docs, but I'm not sure how to actually get all the polyfills.

Up until now, I've been using this import statement:

import VueSimpleSuggest from 'vue-simple-suggest'

It works great in Firefox and Chrome, but IE displays a blank screen with a syntax error pointing to a very long line starting with:

eval("__webpack_require__.r ...

I've also tried this one:

const VueSimpleSuggest = require('vue-simple-suggest/dist/cjs')

But it throws Vue errors, so it seems to be a step in the wrong direction:

  [Vue warn]: Error in created hook: "TypeError: Object doesn't support property or method 'assign'"

Based on what I've read elsewhere, I've specified polyfills in the babel.config.js file:

module.exports = {
  presets: [
    [
      "@vue/app",
      {
        polyfills: [
          "es6.promise",
          "es6.array.iterator",
          "es6.symbol",
          "es6.object.assign",
          "es6.async"
        ]
      }
    ]
  ]
};

and tried forcing babel to transpile dependencies in vue.config.js:

module.exports = {
  transpileDependencies: ["vue-simple-suggest"]
};

But I'm not getting anywhere. Would you be open to going into more detail on how to get the sample app to work in IE 11 from Vue 3.0.1?

Thanks!

How are you importing Vue-simple-suggest?

  • ESNext (original code, single-file .vue component, css included) (import VueSimpleSuggest from 'vue-simple-suggest/lib')
  • ES6 (import VueSimpleSuggest from 'vue-simple-suggest')
  • ES7 and above (import VueSimpleSuggest from 'vue-simple-suggest/dist/es7')
  • Bundled version (import VueSimpleSuggest from 'vue-simple-suggest')
  • CommonJS (const VueSimpleSuggest = require('vue-simple-suggest'))
  • UMD Component (<script type="text/javascript" src="https://unpkg.com/vue-simple-suggest"></script>)

Please tell us about your environment:

  • Vue.js Version: 3.0.1
  • Vue-simple-suggest version: 1.8.2
  • Browser: [IE 11]
  • Language: [| ES6/7 | ES5 ]
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)

destyled prop is not working in source importing

I'm submitting a ...

  • bug report
  • feature request
  • support request

What is the current behavior?

:destyled="true" not working properly when you importing the source: it only affects the input element

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

import VueSuggest from 'vue-simple-suggest/lib'
<vue-suggest :destyled="true" />

What is the expected behavior?

Suggestion items should be destyled as well.

Specify custom input component caveats in the docs

Currently, there's absolutely no clue on what exact API must custom input component expose to work with vue-simple-suggest.

It needs to be specified, I think, that custom input component must:

  • Emit an input event
  • Emit focus and blur events
  • Have a value prop
  • ??? (What else?)

"event" variable should be instantiated for every component instance

I'm submitting a ...

  • bug report
  • feature request
  • support request

What is the current behavior?

All instances of the component are using same component-wide variable event:

It should not be so, because if you instantiate multiple components with different "mode" options, every instance will override this variable for all other instances.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

Instantinate two instances of the component inside the page - first in select-mode, second in input-mode and select-mode component will work as input-mode.

Vue Tips all over console - events must be in kebab-case to work properly

I'm submitting a ...

  • bug report
  • feature request
  • support request

What is the current behavior?

Events are in camelCase and Vue tips all over console, for example:
[Vue tip]: Event "showlist" is emitted in component at node_modules/vue-simple-suggest/lib/vue-simple-suggest.vue but the handler is registered for "showList". Note that HTML attributes are case-insensitive and you cannot use v-on to listen to camelCase events when using in-DOM templates. You should probably use "show-list" instead of "showList".

https://vuejs.org/v2/guide/components-custom-events.html#Event-Names

What is the expected behavior?

https://vuejs.org/v2/guide/components-custom-events.html#Event-Names

What is the motivation / use case for changing the behavior?

Use VueJs best practises to avoid problems.
https://vuejs.org/v2/guide/components-custom-events.html#Event-Names

Please tell us about your environment:

  • Version: 2.0.0-beta.X
  • Browser: [Last Chrome]
  • Language: [ES6/7]

Thank you for very good Select! All other selects around cannot deal with Tab properly, yours can!

Min-length for suggestions to appear

I'm submitting a ...

  • bug report
  • feature request
  • support request

What is the current behavior?

The suggestions appear after the first character has been entered to the input.

What is the expected behavior?

There should be a minLength prop to specify the amount of characters entered before the suggestions trigger (0 or any positive integer). In case of zero the suggestions appear as soon as the input receives focus.

How are you importing Vue-simple-suggest?

  • ESNext (original code, single-file .vue component, css included) (import VueSimpleSuggest from 'vue-simple-suggest/lib')
  • ES6 (import VueSimpleSuggest from 'vue-simple-suggest')
  • ES7 and above (import VueSimpleSuggest from 'vue-simple-suggest/dist/es7')
  • Bundled version (import VueSimpleSuggest from 'vue-simple-suggest')
  • CommonJS (const VueSimpleSuggest = require('vue-simple-suggest'))
  • UMD Component (<script type="text/javascript" src="https://unpkg.com/vue-simple-suggest"></script>)

What is the motivation / use case for changing the behavior?

Different use cases require different approach.
Sometimes you want to query the database once the user has entered at least 2 characters.
Sometimes you want the suggestions dropdown to appear as soon as you click on the input.

Please tell us about your environment:

  • Vue.js Version: 2.5.13
  • Vue-simple-suggest version: 1.7.0
  • Browser: [all]
  • Language: [ ES6 ]

Changing the `mode` on-the-fly doesn't affect the v-model immediately

I'm submitting a ...

  • bug report
  • feature request
  • support request

What is the current behavior?

When you change the mode - v-model doesn't change the value.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

Just bind the mode into a variable and then change it on the runtime.

What is the expected behavior?

v-model should be changed accordingly which mode has been selected

Please tell us about your environment:

  • Vue version: 2.5.16
  • Lib version: 1.5.4
  • Browser: all
  • Language: all

Focus event dont work in Firefox as expected if you click on a item

I'm submitting a ...

  • bug report
  • feature request
  • support request

What is the current behavior?

Whe you click on a autocompeted item firefox seem to loose the focus but .hover class is not removed

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

Create an autcompletion, click on a item...
Click in another part of the page (ex another input)... focus class remain (and i think dont fire event too)

What is the expected behavior?

After click on a item the focus return on the autocomplete input box

How are you importing Vue-simple-suggest?

  • ESNext (original code, single-file .vue component, css included) (import VueSimpleSuggest from 'vue-simple-suggest/lib')
  • ES6 (import VueSimpleSuggest from 'vue-simple-suggest')
  • ES7 and above (import VueSimpleSuggest from 'vue-simple-suggest/dist/es7')
  • Bundled version (import VueSimpleSuggest from 'vue-simple-suggest')
  • CommonJS (const VueSimpleSuggest = require('vue-simple-suggest'))
  • UMD Component (<script type="text/javascript" src="https://unpkg.com/vue-simple-suggest"></script>)

What is the motivation / use case for changing the behavior?

Please tell us about your environment:

  • Vue.js Version: 2.5.0
  • Vue-simple-suggest version: 1.7.0
  • Browser: [Firefox]
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)

if fixed this issue adding the this.inputElement.focus() on suggestionClick function

Class 'hover' is added to all suggestions at once when you're using an array of objects for :list prop.

I'm submitting a ...

  • bug report
  • feature request
  • support request

What is the current behavior?

I'm using an array of objects for :list prop, and when i'm hovering my cursor over suggestions, or when I press up and down keys, class 'hover' added to all of the suggestions, not the only one which i'm hovering my mouse over, or selected with keyboard keys.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

<template>
   <div>
         <vue-simple-suggest
         v-model="skillName"
         :list="array">
             <div slot="suggestion-item" slot-scope="{ suggestion }">
                 {{ suggestion.a}}
             </div>
         </vue-simple-suggest>
  </div>
</template>

This template also gives the same problem:

<template>
   <div class="arbiters-catalog">
       <template>
           <div>
               <vue-simple-suggest
                       v-model="skillName"
                       :list="array"
                       display-attribute="a">
               </vue-simple-suggest>
           </div>
       </template>
   </div>
</template>

Script is the same for both cases.

<script>
    import VueSimpleSuggest from 'vue-simple-suggest';
    export default {
        components:{
            VueSimpleSuggest,
        },
        data:function(){
          return{
              skillName:'',
              array:[{a:'aa'},{a:'ab'},{a:'ac'}]
          }
        },
}
</script>

What is the expected behavior?

It should add 'hover' class only to the selected by keyboard or hovered by cursor item.

How are you importing Vue-simple-suggest?

  • ESNext (original code, single-file .vue component, css included) (import VueSimpleSuggest from 'vue-simple-suggest/lib')
  • ES6 (import VueSimpleSuggest from 'vue-simple-suggest')
  • ES7 and above (import VueSimpleSuggest from 'vue-simple-suggest/dist/es7')
  • Bundled version (import VueSimpleSuggest from 'vue-simple-suggest')
  • CommonJS (const VueSimpleSuggest = require('vue-simple-suggest'))
  • UMD Component (<script type="text/javascript" src="https://unpkg.com/vue-simple-suggest"></script>)

What is the motivation / use case for changing the behavior?

It's a bug, bugs are bad.

Please tell us about your environment:

  • Vue.js Version: 2.5.17
  • Vue-simple-suggest version: 1.8.0
  • Browser: [Chrome 65.0.3325.181 | Firefox 61.0.1]
  • Language: [ES6/7]

##This is how it looks
2018-08-14 15-34-00 1
2018-08-14 15-14-56 1

Impossible to set default value with v-model / value

I'm submitting a ...

  • bug report
  • feature request
  • support request

What is the current behavior?

My Component

<vue-simple-suggest :value="localUser.tiers_num" :list="tiers"  @input="getTiersList" value-attribute="id" display-attribute="disp">
    <input class="form-control" >
</vue-simple-suggest>

## localUser.tiers_num contain '000041'

Function getTiersList

getTiersList: (q)->
      @.$store.dispatch 'user/getTiers', q

Actions getTiers (in my state)

rest.getData('tiers?q=' + q).then (res)=>
      { rows } = res
      commit "setTiers", rows

## Where rows like : 
[
    { "l":"JEAN VALJEAN", "disp":"[000041] JEAN VALJEAN", "id":"000041"}
]

What is the expected behavior?

I expect to have my default value SET, but it's not the case...
I probably have a wrong way to do things...

When my vue is Mounted, my list is empty, it's when I begin to xrite something that the AJAS populate the list on the fly.

At first, i have the feelings that the default value must be in my list, is that right ?
Secondly, I don't know if I must put an object or just ths ID in my v-model, i tried both, but nothing work.

Thanks for the help

How are you importing Vue-simple-suggest?

  • ESNext (original code, single-file .vue component, css included) (import VueSimpleSuggest from 'vue-simple-suggest/lib')
  • ES6 (import VueSimpleSuggest from 'vue-simple-suggest')
  • ES7 and above (import VueSimpleSuggest from 'vue-simple-suggest/dist/es7')
  • Bundled version (import VueSimpleSuggest from 'vue-simple-suggest')
  • CommonJS (const VueSimpleSuggest = require('vue-simple-suggest'))
  • UMD Component (<script type="text/javascript" src="https://unpkg.com/vue-simple-suggest"></script>)

Please tell us about your environment:

  • Vue.js Version: 2.5.16
  • Vue-simple-suggest version: latest
  • Browser: Chrome
  • Language: ES6/7 / Coffeescript

Using valueAttribute value in v-model?

Does the autosuggest component currently support using the value from an object property by defining it in valueAttribute?

For example given, an example array of objects:

[
  {
    "id": 1,
    "name": "Item 1"
  },
  {
    "id": 2,
    "name": "Item 2"
  }
]

And an example usage:

<autosuggest :list="getList" display-attribute="name" value-attribute="id" v-model="selectedId" />

If I select a suggestion, would I be able to get selectedId v-model to equal that of an object id property? Currently based on testing I wasn't able to.

Rename `list` prop into `source`

I'm submitting a ...

  • bug report
  • feature request
  • support request

What is the motivation / use case for changing the behavior?

It would be more convenient, since source is lexically more general than list.

Potential milestone for next version.

Ability to choose v-model type (object/string/index)

I'm submitting a ...

  • bug report
  • feature request
  • support request

What is the current behavior?

v-model binds only a displayed attribute of an item (i.e. string)

What is the expected behavior?

v-model binds a string (as default), a full item (object) or item's index in the list, depending on some property's value.

The property in question can be named something like v-mode. Or maybe something less ambiguous.

What is the motivation / use case for changing the behavior?

Ability to choose the component mode depending on the circumstances. (Usability)

Custom `input` bound to `v-model` doesn't respect selection changes.

I'm submitting a ...

  • bug report
  • feature request
  • support request

What is the current behavior?

Inserting a custom <input> allows me to format, and set specific values such as required for validation. However, there becomes a conflict with v-model such that it doesn't respect manual changes. The "suggestion" box pops up correctly, however, when a value is selected, the pre-existing value remains firmly. This problem, of course, goes away, if there is no custom <input>

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

               <vue-simple-suggest
                  :styles="autoCompleteStyle"
                  :list="arrayStateProvince"
                  :filter-by-query="true"
                  v-model="project.state_province"
                >
                  <!-- <input class="form-control" v-validate="'required'" required> -->
                </vue-simple-suggest>

Without v-model on input, it won't display the initial value when the form is loaded from the data source. If I add v-model="project.state_province to the custom <input> instance, when the form loads from the data source it fills correctly, but I can never change it. Yes the suggestions still pop up (I'm guessing because that functionality is independent), but when I select one it "flickers" and goes back to the original value.

What is the expected behavior?

How do I fully customize <input> while still allowing it to behave as "normal" and respect v-model?

How are you importing Vue-simple-suggest?

  • ESNext (original code, single-file .vue component, css included) (import VueSimpleSuggest from 'vue-simple-suggest/lib')
  • ES6 (import VueSimpleSuggest from 'vue-simple-suggest')
  • ES7 and above (import VueSimpleSuggest from 'vue-simple-suggest/dist/es7')
  • Bundled version (import VueSimpleSuggest from 'vue-simple-suggest')
  • CommonJS (const VueSimpleSuggest = require('vue-simple-suggest'))
  • UMD Component (<script type="text/javascript" src="https://unpkg.com/vue-simple-suggest"></script>)

I'm importing it globally in main.js though as a component. It seems to work in all cases except where I need to fully customize input.

What is the motivation / use case for changing the behavior?

In this particular case, I simply want the ability to validate and require the input values natively.

Please tell us about your environment:

  • Vue.js Version: 3.0.0-beta.15
  • Vue-simple-suggest version: 1.8.2
  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
  • Language: [ES6/7 ]
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.