0.1.12 • Published 7 years ago

suggestive-text-field v0.1.12

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

Suggestive Text Field

The most basic autocomplete input on the web. Comes as a single JS file that doesn't depend on anything.

  textInput = document.querySelector('input[name=tags]')
  new SuggestiveTextField(textInput, ['monster', 'monstrosity', 'trap'])

demonstration

Okay, but my autocomplete needs to fetch the suggestions dynamically

new SuggestiveTextField(textInput, null,
  suggestionsForToken: (token) ->
  
    new Promise (resolve, reject) ->
      remoteJSON "http://api.cdek.ru/city/jsonp.php?name_startsWith=#{token}", (response) ->
        resolve response.locations.map (location) -> location.cityName
        
)

More details right below. remoteJSON is just a jQuery-free replacement for $.getJSON() from here.

Options

SuggestiveTextField(textInput, suggestions, {

  tokenSeparator: ', ', // or pass false to disallow multiple selections
  minTokenLength: 1, // how many symbols user has to type to trigger suggestions
  
  // Pass your own functions as hooks to alter the behaviour:
  
  suggestionsForToken: function (token) {
    // Return suggestions that match `token`
    // as array of strings or array of objects (must have `text` property).
    // If your operation is async, return a Promise.
  },
  onConfirmHook: function (selectedSuggestion) {
    // Do something extra when a suggestion is selected
  }
})

Development

blade runner to run the tests in the browser blade build to re-compile the dist/

0.1.12

7 years ago

0.1.11

7 years ago

0.1.10

7 years ago

0.1.9

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.0

7 years ago