Skip to content
This repository has been archived by the owner on Oct 5, 2023. It is now read-only.

Latest commit

 

History

History
71 lines (54 loc) · 2.6 KB

File metadata and controls

71 lines (54 loc) · 2.6 KB

jquery.ui.autocomplete.localcache

jQuery UI Autocomplete Extension to support local + remote results via AJAX

Why choose between a static list of local results for autocomplete and waiting for AJAX responses to load information? This extension provides the best of both worlds by searching a local cache of results immediately while additional results are loaded from the server in the background.

Demo

Core jQuery UI Autocomplete Documentation

Usage

// initial local cache of results
var localCache = [
  {label: "Java", value: 'java'},
  {label: "Ruby", value: 'ruby'}
];
$('input').autocomplete({
  cache: localCache,
  remoteSource: function(request, response) {
    return $.getJSON('/some/search/endpoint', function(data) {
      response(data);
    });
  }
});

Features

  • Searches local cache of entries before waiting for AJAX request/response.
  • When AJAX response returns, new results are appended to the existing suggestions.
  • Results from each AJAX response are stored in the local cache to increase speed of future searches.

Installation

  • Ensure all JS dependencies are included in your page
  • Include jquery.ui.autocomplete.localcache.js script
  • Initialize the jQuery UI autocomplete component with localcache configuration.

Configuration

Required and optional configuration for the local cache plugin.

  • cache - an array of objects to initialize the local autocomplete cache. The data format for cached entries must contain a label and value property per the jQuery UI Autocomplete API. An empty array is also acceptable.
  • remoteSource - a function that creates a jqXhr to lookup additional suggestions. The function takes two parameters: request and response mirroring the default jQuery UI Autocomplete source option (see docs).
  • remoteDelay - number of milliseconds to wait between local search and firing remote ajax call (default = 200)

Contributing

Copyright

Copyright (c) 2012 VMware, Inc. All Rights Reserved. See Project license for additional details.