Giter VIP home page Giter VIP logo

simple-svelte-autocomplete's Introduction

Simple Svelte Autocomplete

Autocomplete / Select / Typeahead component made with Svelte

  • no dependencies
  • use plain lists or array of objects
  • option to define a label field or function
  • option to define more fields used for search
  • support for async load of items
  • can hold one or several values

Install

npm i -D simple-svelte-autocomplete

Usage

Import the component and define items:

import AutoComplete from "simple-svelte-autocomplete"

const colors = ["White", "Red", "Yellow", "Green", "Blue", "Black"]
let selectedColor

And use it like this:

<AutoComplete items="{colors}" bind:selectedItem="{selectedColor}" />

You can also use it with array of objects:

const colorList = [
  { id: 1, name: "White", code: "#FFFFFF" },
  { id: 2, name: "Red", code: "#FF0000" },
  { id: 3, name: "Yellow", code: "#FF00FF" },
  { id: 4, name: "Green", code: "#00FF00" },
  { id: 5, name: "Blue", code: "#0000FF" },
  { id: 6, name: "Black", code: "#000000" },
]

let selectedColorObject

Just define which field should be used as label:

<AutoComplete items="{colorList}" bind:selectedItem="{selectedColorObject}" labelFieldName="name" />

Specifying function for label instead of field name is also supported:

<AutoComplete items={colorList} bind:selectedItem={selectedColorObject} labelFunction={color =>
color.id + '. ' + color.name} />

By default the component searches by the item label, but it can also search by custom fields by specifying keywords function. For example to enable searching by color name and color HEX code:

<AutoComplete items={colorList} bind:selectedItem={selectedColorObject} labelFieldName="name"
keywordsFunction={color => color.name + ' ' + color.code} />

Asynchronous loading of items

Define a searchFunction which will be called with keyword and maxItemsToShowInList parameters. If you have searchFunction defined you don't need to specify items since the function will be used for loading. The delay parameter specifies the time to wait between user input and calling the searchFunction. It is recommend that delay > 200ms is set when using a remote search function to avoid sending too many requests. The localFiltering parameter can be set to false if the search function already returns filtered items according to the user input.

<AutoComplete
  searchFunction="{getItems}"
  delay="200"
  localFiltering={false}
  labelFieldName="name"
  valueFieldName="id"
  bind:selectedItem="{myValue}"
/>
async function getItems(keyword) {
  const url = "/api/my-items/?format=json&name=" + encodeURIComponent(keyword)

  const response = await fetch(url)
  const json = await response.json()

  return json.results
}
{
  "results": [
    {
      "id": 1,
      "name": "Sample One",
      "date": "2020-09-25"
    },
    {
      "id": 2,
      "name": "Sample Two",
      "date": "2020-09-26"
    }
  ]
}

Properties

Behaviour

  • items - array of items the user can select from (optional, use searchFunction for async loading of items)

  • searchFunction - optional function to load items asynchronously from HTTP call for example, the searchFunction can also return all items and additional local search will still be performed

  • delay - delay in milliseconds to wait after user input to do the local searching or call searchFunction if provided, defaults to 0

  • localFiltering - boolean specifying if searchFunction is used, to still perform local filtering of the items to only ones that match the user input, defaults to true

  • localSorting - boolean specifying if result items should be sorted locally by itemSortFunction or sortByMatchedKeywords. If set to false, no local sorting will be done

  • cleanUserText - by default the component removes special characters and spaces from the user entered text, set cleanUserText=false to prevent this

  • multiple - enable multiple selection (false by default)

  • orderableSelection - enable selection reordering with drag and drop. needs multiple = true

  • selectedItem - the current item that is selected (object if the array of items contains objects)

  • highlightedItem - the current item that is highlighted in the dropdown menu

  • labelFieldName - the name of the field to be used for showing the items as text in the dropdown

  • keywordsFieldName - the name of the field to search by, if not specified the label will be used

  • value - derived value from the selectedItem, equals to selectedItem if valueFieldName is not specified

  • valueFieldName - field to use to derive the value from the selected item

  • labelFunction - optional function that creates label from the item. If used labelFieldName is ignored

  • keywordsFunction - optional function that creates text to search from the item. If used keywordsFieldName is ignored

  • valueFunction - optional function that derives the value from the selected item. If used valueFieldName is ignored

  • keywordsCleanFunction - optional function to additionally process the derived keywords from the item

  • lowercaseKeywords - set to false to not lowercase the keywords extracted from the items

  • textCleanFunction - optional function to additionally process the user entered text. Ignored if cleanUserText=false

  • selectFirstIfEmpty - set to true to select the first item if the user clears the text and closes the dropdown, defaults to false

  • minCharactersToSearch - minimum length of search text to perform search, defaults to 1

  • maxItemsToShowInList - maximum number of items to show in the dropdown list, defaults 0 (no limit)

  • ignoreAccents - ignores the accents/umlauts (è,ü,ö etc) to match items, defaults to true

  • matchAllKeywords - defaults to true, if false, any item will be suggested if it shares at least one common keyword with the input. Ignored if sorting function is given with itemSortFunction

  • sortByMatchedKeywords - defaults to false, if true, items are sorted by the number of matched keywords, only useful if matchAllKeywords is false. Ignored if sorting function is given with itemSortFunction

  • itemSortFunction - Optional custom function to order items. Parameters are two list items to compare and the cleaned up search query. Returns an integer indicating wether the first item comes before the seconde one. Only used if sortByMatchedKeywords is true.

  • itemFilterFunction - Optional custom function to filter items. Parameters are a list item and the cleaned up search query. Returns a boolean indicated wether to keep the item. If this is used, the keywordsFieldName and keywordsFunction are ignored

  • disabled - disable the control completely

  • readonly - make the input readonly, no user entered text (simulates combobox), item from the list can still be selected

  • lock - defaults to false, locks the input for user entered text when an item has been selected

  • create - true to enable accepting of unlisted values

  • closeOnBlur - true to close the dropdown when the component loses focus

  • debug - flag to enable detailed log statements from the component

Events

  • beforeChange - function called before a new value is selected
  • onChange - function called after new value is selected
  • onFocus - function called on focus of the input control
  • onBlur - function called on blur of the input control
  • onCreate - function called when create is true and the user presses enter, the function must return add the created item to the items array and return it

UI options

  • placeholder - change the text displayed when no option is selected
  • noResultsText - text to show in the dropdown when the search text does not match any item. Defaults to "No results found". Can be set to "" to not show anything.
  • moreItemsText - text displayed when the user text matches a lot of items and we can display only up to maxItemsToShowInList items
  • createText - text to show when create is true, and the user text doesn't match any of the items
  • hideArrow - set to true to not show the blue dropdown arrow
  • showClear - set to true to show X button that can be used to deselect the selected item
  • showLoadingIndicator - defaults to false, set to true to show loading spinner when the async searchFunction is executed, bulma class 'is-loading' is added to the input control

CSS classes and IDs

  • className - apply a className to the control
  • inputClassName - apply a className to the input control
  • noInputStyles - set to true to disable the input autocomplete-input classes which are added to the input by default
  • inputId - apply an id attribute to the the input control
  • dropdownClassName - apply a className to the dropdown div showing the list of items
  • name - generate an HTML input with this name, containing the current value
  • html5autocomplete - value to enable or disable the HTML5 autocomplete attribute.
  • autocompleteOffValue - the value when html5autocomplete=false, defaults to off but can be set to none for Chrome
  • selectName - apply a name attribute to the tag that holds the selected value selectId - apply an id attribute to the tag that holds the selected value
  • required - adds the required attribute to the input
  • tabIndex - adds the tabIndex attribute https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex

UI Slots

  • item - change the apearance of items in the dropdown list:
<div slot="item" let:item let:label>
  {@html label}
  <!-- to render the default higliglighted item label -->
  <!-- render anything else -->
  <span style="color:{item.propertyX}">{item.propertyY}</span>
</div>
  • no-results - customize the div that shows the "no results" text:
<div slot="no-results" let:noResultsText>
    <span>{noResultsText}</span>
</div>

The noResultsText variable is optional and can be ommited.

  • loading - customize the div that shows the "loading" text:
<div slot="loading" let:loadingText>
    <span>{loadingText}</strong>
</div>
  • tag - customize the tag blocks displayed when multiple selection is enabled:
<div slot="tag">
  <span class="tag">{label}</span>
  <span class="delete-tag" on:click|preventDefault="{unselectItem(item)}"></span>
</slot>
  • dropdown-header - customize what is displayed before the item list in the dropdown. By default there is nothing displayed.
<div slot="menu-header" let:nbItems let:maxItemsToShowInList>
  <div class="dropdown-item">Choose between those {nbItems} items</div>
  <hr class="dropdown-divider">
</div>
  • dropdown-footer - customize what is displayed after the item list in the dropdown. By default this is where the moreItemsText is displayed if there are too many items to be displayed.
<div slot="dropdown-footer" let:nbItems  let:maxItemsToShowInList>
    ...
</div>

CSS properties

  • autocomplete the class applied to the main control
  • autocomplete-input the class applied to the input list
  • autocomplete-list the class applied to the dropdown list
  • autocomplete-list-item the class applied to items in the dropdown list

Note: Setting noInputStyles=true will disable the use of the autocomplete-input class above.

Use global to apply styles, example:

  .parent :global(.childClass) {
    color: red;
  }

The component is inteded to use with Bulma but it can be adapted to use Boostrap or anything else.

simple-svelte-autocomplete's People

Contributors

abovethewater avatar alexastall avatar alpozcan avatar azmeuk avatar bulatshafigullin avatar daniel17903 avatar dependabot[bot] avatar frederikhors avatar gtim avatar hugome avatar jieter avatar joetm avatar kmielke avatar leovoon avatar mihai-bumb avatar paulschreiber avatar pglivicky avatar pstanoev avatar ryanblanks avatar sdwvit avatar woodyrew avatar wykhuh 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

simple-svelte-autocomplete's Issues

Only display the arrow when list items are available

The right arrow is always displayed, even when no data is available. This might be confusing for end-users.

Screenshot_2021-04-09 Svelte Simple Autocomplete Demo

I suggest hiding the arrow when no data is available, or at least grey it does not call for a user action.

What do you think?

accept unlisted items

Hello,

is there a way to accept unlisted items ? I mean if the autocomplete component used the list ['one','two','three'] is it possible to make accept value 'four' ?

thanks,

Dropdown list does not close if the last character is deleted

If I search, and then backspace to the point I remove the last character, then the dropdown list still remains with the last list visible.

My current workaround is to set minCharactersToSearch=2, as this functions as expected.

It looks to be related to line 590 of SimpleAutocomplete.svelte:

  function isMinCharsToSearchReached() {
    return (
      minCharactersToSearch > 1 && filteredTextLength < minCharactersToSearch
    );
  }

  function closeIfMinCharsToSearchReached() {
    if (isMinCharsToSearchReached()) {
      close();
    }
  }

if minCharactersToSearch is 1, then it'll never close.

Why is this logic explicitly excluding the default use case (minCharactersToSearch is 1)?
If this is intentional functionality then I'd ask for an option to closeOnEmpty.

I'm using the autocomplete async if that is relevant.

Thanks for the really useful library :)

Undefined className leads to "undefined" in HTML

Because className defaults to undefined, the literal string undefined appears in the markup, i.e.

<div class="undefined autocomplete select is-fullwidth sautocomplete-763 svelte-gfsz5d">

Possible fixes:

  • default className to ''
  • output an empty string if className is falsy <div class="{className || ''} autocomplete select is-fullwidth {uniqueId}">

Using key for objects

https://svelte.dev/repl/f88cf2ad315a419ea4e737e18b612a9e?version=3.23.2

I have an array of options.
I see the valueFieldName option to say which key to use as the value.

But when I bind to it with bind:value, it's not two-way -- when I change it elsewhere, it doesn't update locally. Also, when I initialize with a value, it seems to get overwritten.

Using bind:selectedItem works, but then I'm passing unnecessary nested data back and forth. I'm guessing that when I change a label name, the key won't match anymore either.

Expected result: when using valueFieldName, if the options are objects but the value is a string, it should find the option by the valueFieldName.

EDIT: to be clearer: when setting the value in the third box to one of the keys, I expect the autocomplete box to change.

Clicking away from the input and then back loses the matched text highlighting

When the user clicks away from the input box then it closes. When it reopens the current search is still available, based on what is still in the input.

However, when they do this, the bold effect on matched words is lost.

This is due to the line:

filteredListItems = listItems; in resetListToAllItemsAndOpen()

If this line is commented, then it behaves as I would expect (text is in input box and matches are highlighted in the dropdown).

I imagine for a static list you may want to reset this if the list is empty, so suggest this is simply wrapped:

    if (text === "") {
      filteredListItems = listItems;
    }

Ignore non listed items

When i type a non listed text, and i press enter i get this:

SimpleAutocomplete.svelte:310 Uncaught TypeError: Cannot read property 'item' of undefined
    at selectListItem (SimpleAutocomplete.svelte:310)
    at selectItem (SimpleAutocomplete.svelte:321)
    at HTMLInputElement.onKeyPress (SimpleAutocomplete.svelte:430)
selectListItem @ SimpleAutocomplete.svelte:308
selectItem @ SimpleAutocomplete.svelte:320
onKeyPress @ SimpleAutocomplete.svelte:429

so you have to ignore non listed items from event!

Lock the input

I suggest adding an option to lock the input. This would be useful when one wants to prevent users to submit entries that are not taken from the suggestion list. Here is the scenario:

  • the user types thing in the input field
  • the suggestions list opens, the user selects an option
  • now the user cannot edit the input field, but a small cross has appear on the right of the field
  • the user clicks on the cross, or presses backspace
  • the field value is reset, the user can edit the input field again

What do you think?

Async support?

I would love to use this with async, any plans to add that?

Allowing typed entries

Is there a way to allow users to type an entry that is not in the list? (not sure of the technical name for this behavior). The user could select one of the autocomplete entries, or type a new one?

'value' seems to never be used

The value variable is computed alongside the text variable when an item is selected.

function onSelectedItemChanged() {
value = valueFunction(selectedItem);
text = safeLabelFunction(selectedItem);
onChange(selectedItem);
}

However, value is never read anywhere else in the code, nor bound to anything. I would have expected value to be bound to the input value attribute, but this is actually text that is:

When submitting the form, the input indeed holds the text value. This seems like a bug to me.
What do you think?

Ability to deselect item

Once you select an item, there is no way to unselect it. It would be handy to include a way to clear the selection (perhaps an "X").

image

Asynchronous Submit Feature

In this scenario, async calls are made to a server api which searches in cache. If no results are returned, does this component allow a submit event to the server via user pressing enter key or some button?

Attribute autocomplete on <input>

Hi,

The browser's inbuilt autocomplete functionality is interfering with the simple-svelte-autocomplete list of matches. There is a simple fix. Add the attribute autocomplete="off" to the <input> element at around line 614. See MDN for more details.

BTW, this is a great component, very easy to use.

Dispatch to Parent Component

I can't seem to dispatch events from the Autocomplete component to a Parent component in Svelte. The binding works perfectly, however, I need to be able to use a function which does not seem to work.

function change(event){
ticker = "change"
data = event.target.value
}

{#if ticker === "overview"}
<AutoComplete bind:selectedValue on:change={change} />
{#if ticker === "change"}


Autocompletion fails with accents

For instance, if there is an item téléphone in the list and the user types tele the item won't be suggested.
Latin languages use a lot of accents, and they are a recurrent source of typos, so that would be great if the component could manage those cases.

Activity indicator

When searchFunction requests take a long time, there is no visual indicator showing that the request is sent. I suggest implement a spinner in those cases.

Some inspiration here

html on labelFunction also gets searched

Below is my code.
<AutoComplete items={countries} bind:selectedItem={selectedCountry} labelFunction={c => '<a href="' + c.url + '"><span class="flag-icon ' + c.flag + '"> </span>' + c.name + '</a>'} keywordsFunction={c => c.name} />
When I type the letter "a" it seems to be searching all the HTML inside .autocomplete-list-item where I expect it to use the keywordsFunction to search for the keyword.
Is this an issue or I'm doing something wrong?

Pass 'maxItemsToShowInList' to 'searchFunction'

I suggest passing maxItemsToShowInList to the searchFunction.

This way the number of elements can be sent serverside, and would allow a server to only set the right number of elements in the response, and then save some bandwidth.

What do you think?

onChange gets triggered on parent component mount

The onChange function set up in the Autocomplete component gets triggered twice before I even do anything. How to stop that? It should only trigger once the Autocomplete input box has lost focus.

.focus method

Thanks for the great component. It would be great if it exported a .focus method that focused on the input. The workaround is to use itemId and getElementById... but... would be handy. (thanks for fixing the itemId extra space, I ran into an issue with that and noticed that it was fixed with an npm update).

too much requests are generated

If someone types a query very fast, say lorem ipsum dolor, a lot of network request will be generated (l, lo, lor, lore, lorem, lorem , lorem i ...). This causes several issues:

  • the only useful query is lorem ipsum dolor
  • ajax response may not come in the order they were sent, this leads to suggesting old queries while ignoring the current one. For instance the response for the lor query might come after lorem ipsum dolor, so the completion will be proposed for lor instead of lorem ipsum dolor.
  • search queries might be slow on a server, sticking to the minimum useful queries might be a good idea

I can see several leads to fix this:

  • Only send a request after there has been some inactivity on the field (i.e. wait a few milliseconds). That would probably go unnoticed by the end-user, but that may reduce the number of queries.
  • Add a marker on each request, and expect the answer to have the same marker. This way the client side can know which request has been sent the last, and it can ignore old request coming too late. We can insipire on the draw attribute on Datatables serverside processing mechanism. I suggest passing a draw parameter to the searchFunction that would be an increasing integer, and expect this same draw parameter to be returned by searchFunction. The search method would keep track of the highest draw values returned from searchFunction calls and would ignore all calls with a draw value below this.

What do you think?

Handle multiple values

This component allows to select a single value from a list of suggestions. There are usecases where several values need to be collected.

I suggest making this component able to deal with several values:

  • either by enabling a multiple option (my favorite),
  • or by implementing another MultipleSvelteAutocomplete component (and factorize the common code of the two components)

The result could integrate well with bulma tags, and look like this:

tags

The list of values can be stored:

  • use <select multiple> instead of <input> in those cases
  • either in the <input> value parameter, with a configurable separator (e.g. , or ; or )
  • either in several <input type="hidden" name={name}>

What do you think?

Reduce duplicate the labels

I am using this plugin to filter products and categories.
For the label I use the categories.

In the select dropdow there are as many categories as there are products. So there are plenty duplicate categories shown.

is it possible to reduce the dropdown categories?
labelFunction={item => item.category}
maybe like
labelFunction={new Set(item => item.category)}

Some small potential improvements & issues

Hey, first off thanks a lot for resurrecting the old svelte 2.x autocomplete and bringing it into the svelte 3.x world. I usually have pretty good google-fu, but I almost gave up in finding a good, but simple and easy to use autocomplete solution for a svelte 3.x app I'm developing, would have even been happy to use some non-bloated non-svelte version.

Anyway, I have a few suggestions for improvements to this library (and some minor issues, too) that I'd like to share, and hopefully someone (maybe even myself) will pick them up and do something productive with them!

  • when I've already selected an item and click the autocomplete again, I may want to type something new now and would expect the autocomplete to select the text in there for me, so I can overwrite it without having to delete it first --> auto-select text contents when focused
  • I don't necessarily want to keep displaying the text that has been entered or selected in the autocomplete field; sometimes I'd prefer to just show it as empty (ideally with an icon in there that signals "search/filter"), sometimes I'd want to just keep the text the user entered instead of changing the text to what ended up being selected
  • when the autocomplete field is focused, I'd expect pressing ESC to clear its text contents (or revert to the previous selection / text if there was one and I started making changes, but then decided to abort midway through before making a new selection; but this part is already beyond what I really need / imagine at the moment)
  • maybe the field could also provide an "X" icon on the right, to allow less keyboard-hotkey-savvy users to also easily clear the selection
  • blue arrow overlapping text if text is long, making it non-recognizable and not user friendly when that happens

To provide a small bit of context about the use case here, in the current instance I'm using the component to control a multi-level (tree-style) navigation bar that allows direct jumping (to leaf nodes) instead of navigating via multiple clicks. So it's less of a form-field type usage and more of a persistent and repeatedly re-used search/filter/navigation element where "current state" is a lot less important (after selection) than the re-occurring event of typing/filtering and selection itself.

I'll leave this post as is for now, might get back to it later. I feel like some thinking about if any of this doesn't fit in with the simple "vision" for this component could be good, as well as considering how these might be implemented while keeping or even simplifying the API further. But brain doesn't want to do that right now, brain seems tired. :D

Cheers
Denis

More flexible keywords matching strategy

Let suppose I have a list of several items matching common keywords: ["White Rabbit", "White Horse", "Black Rabbit", "Black Horse"]

  • If input is White, then White Rabbit and White Horse are suggested. This far the behavior is as expected.
  • If input is White Rabbit, then only White Rabbit is suggested. This shows that the current behavior is that all the typed words must be found in the items keywords to appear in the suggestion list. This behavior can be useful, but sometimes one might want to suggest more loose results. For instance we could expect that typing White Rabbit would suggest White Rabbit, White Horse and Black Rabbit. That would imply to list every item matching at least one input word, and order them depending on the number of matched keywords.
  • If input is Rabbit White, then nothing is suggested. This is unexpected as all the input keywords are present in White Rabbit.
  • If input is White Cat then nothing is suggested. Here I would have expected White Rabbit and White Horse

I suggest:

  • adding a parameter matchAllKeywords that would be True by default (the current behavior). When False an item would appear in the list if it contains at least on keywords.
  • order the items in the list, starting with the items that contains the more keywords.
  • ignore the order for the keywords suggestion (so white rabbit and rabbit white are the same)

What do you think?

debug=true causes compile error. "performance" not available server side / in SvelteKit

Using this library with SvelteKit causes vite to fail to compile if debug=true is used.

performance is not defined
ReferenceError: performance is not defined
    at prepareListItems (SimpleAutocomplete.svelte:185:12)
    at SimpleAutocomplete.svelte:233:28

Obviously performance is only available in the browser.
Wrapping these calls in if (process.browser) { ... } allows it to compile, but that's a hack.

perf_hooks provides the performance API, but is an external / node specific dependency.

Customize the list items

At the moment, the list items are statically defined, and let no room for customization.

<div
class="autocomplete-list-item {i === highlightIndex ? 'selected' : ''}"
on:click={() => onListItemClick(listItem)}
on:pointerenter={() => {highlightIndex = i;}}>
{#if listItem.highlighted}
{@html listItem.highlighted.label}
{:else}
{@html listItem.label}
{/if}
</div>
{/if}

Those are thing I miss:

  • I would love to be able to change the items style;
  • I would also love to be able to add context to the list item with some variables from the objects list. For instance with the colors example in the README.md file, this would allow to display the color names colorized with their actual color codes. This would be particularly useful to add context in cases when several elements in the list have the same label, but could be differentiated by a bit of context otherwise;
  • I would like to be able to do a little more complex HTML here.

I can give a try and submit a patch. I suppose than slots can be useful here.

What do you think?

When having two Autocomplete boxes on the same page, both stay open

First of all thanks for your work! Was easy to setup and implement!

I have the following problem: If I have two Autocomplete elements on one page and the user clicks from one open to the next - both stay open. Only a click outside of the Autocomplete triggers a close it seems, not a click to another one.

Is there any way to close an Autocomplete programmatically? Or perhaps my use case would be better solved if a click into another Autocomplete would trigger a close itself.

SMA240wyer

Autocomplete HTML5 parameter

Hi. Sometimes the native browser autocomplete menu is displayed at the same time as this module. I suggest adding a autocomplete parameter that would trigger the HTML5 autocomplete parameter. I would also suggest this being false by default.

What do you think?

When labelFunction is defined, search fails unless keywordsFieldName is also present

When labelFunction is defined, search fails unless keywordsFieldName is also present. You see "No results found":
image

Enabling debug shows:

Extracted keywords: '[object object]' from item: {"url":"http://127.0.0.1:8000/api/organizations/198/?
format=json","id":198,"name":"East Palo Alto","notes":""}

works (labelFunction + keyworksFieldName):

<AutoComplete searchFunction={getAgencyList} labelFunction={getAgencyLabel} keywordsFieldName="name" 
valueFieldName="id"

works (labelFieldName, no keyworldsFieldName):

<AutoComplete searchFunction={getAgencyList} labelFieldName="name" valueFieldName="id"

fails (labelFunction, no keyworldsFieldName):

<AutoComplete searchFunction={getAgencyList} labelFunction={getAgencyLabel} valueFieldName="id"

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.