Giter Club home page Giter Club logo

auto-complete's Introduction

⚠️ This project is archived and the repository is no longer maintained.

Auto-complete

Filament Group

A lightweight auto-complete that can be populated via JSON or by DOM element text.

Build status

Dependencies

  1. jQuery or Shoestring
  2. Menu

Setup

Use the following includes to setup the init on enhance:

<script src="lib/shoestring-dev.js"></script>
<script src="lib/menu.js"></script>
<script src="src/core.js"></script>
<!-- optional if you're not using a DOM source for data -->
<script src="src/dom.js"></script>
<script src="src/init.js"></script>
<link rel="stylesheet" href="/lib/menu.css">

Typically the enhancement is triggered on DOM ready and when subsequent markup is added to the page:

$( function(){ $(document).trigger("enhance"); } );

Options

  • data-best-match, if the input has this attribute, on blur, the first match in the current suggested matches will be used to populate the input.

Examples:

See the demo page for examples.

Custom Comparison Logic

The existing comparison (which is just a substring check) might be too simple. In this case you can replace the compareDataItem definition on the AutoComplete prototype to get the desired custom comparison functionality. For example if you wanted to consult another part of the DOM (eg an input) for information that might inform the filtering of auto complete data you might do the following:

// data : String, a data item from the auto-complete data source (DOM or Ajax Req)
// val : String, the value of the auto-complete input
w.componentNamespace.AutoComplete.prototype.compareDataItem = function(data, val){
  // get the extra constraint information from the DOM
  var otherConstraint = $( ".some-input").val();
  
  // check if the value from the other input is a substring of the auto-complete data
  // check if the value from the autocomplete input is a substring of the auto-complete data
  // return true if both constraints are satsified
  return data.indexOf(otherConstraint) > -1 && data.indexOf(val) > -1;
}

As long this definition is executed after the auto-complete library is loaded/executed then this new method definition will determine the logic that plugin uses to filter the incomeing auto-complete data.

NOTE that the component namespace is often defined per-project. If you have defined that to be something other than componentNamespace which is the default, you'll need to substitute that here.

AUTO-complete

Just a bit of fun:

We define a class of languages AUTO, such that L is in AUTO if there exists a Turing machine M and an oracle O where M can write its input on the oracle tape and respond directly with the oracle's answer in a single query and L is decided by M.

Lemma 1. The language decided by the auto-complete component is in AUTO.

Clear from the implementation of the component. ∎

Lemma 2. All languages in AUTO can be reduced in polynomial time to the language decided by auto-complete.

Follows directly from the observation that the component takes as one of its parameters the "URL" for the oracle which it will consult. As a result we can always simulate the Turing machine for another language in AUTO by taking both the input and the URL for the oracle used in the implementation of the corresponding Turing machine which ensures that it will always have "the right oracle" to answer queries in a single round for any language in AUTO. ∎

Theorem. The language decided by the auto-complete component is AUTO-complete

By Lemma's 1 and 2. ∎

auto-complete's People

Contributors

jefflembeck avatar johnbender avatar scottjehl avatar tomgreenhill avatar zachleat 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

Watchers

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

auto-complete's Issues

Regression with arrow keys and menu

Hitting the arrow keys calls render again every time, which blows away the selected value.

It looks like gh-pages is still working (and a bit outdated) so this is probably a recent regression.

I have a fix for this working locally and I’ll PR it, you might have a better way to solve this.

Phantom first value placeholders

ENHANCEMENT logged for posterity

image

The text that would autocomplete if you selected the first entry shows in the text field.

It doesn’t have to be styled gray necessarily but we could just insert it as Selected Text, so any subsequent typing would overwrite it.

Lag when typing on iPad iOS 9

When typing to search for an option on an iPad (versions tested were iOS 9.1 and 9.2) there is a noticable lag in the characters appearing on the screen. The same is true for when removing characters by using the Backspace key.

Option to disallow entries not in the data.

If not a valid entry present in the data source:

  • Select best match on blur
  • If no matches apply, clear any text in the field.

This might be better tied to a validation framework?

Option to run different filtering algorithm / regex

Having only the one algorithm to filter results limits the functionality available for filtering various results. For example - having two possible options - "United States of America" and "United Kingdom". Currently if the user types "United", then both options will appear but if the user enters "America" we would like for the filtering to pick up on "United States of America".

Is there a possibility of having the ability to change the search / regex used?

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.