{"id":13602745,"url":"https://github.com/devbridge/jQuery-Autocomplete","last_synced_at":"2025-04-11T09:30:56.873Z","repository":{"id":398930,"uuid":"688157","full_name":"devbridge/jQuery-Autocomplete","owner":"devbridge","description":"Ajax Autocomplete for jQuery allows you to easily create autocomplete/autosuggest boxes for text input fields","archived":false,"fork":false,"pushed_at":"2023-10-11T00:51:21.000Z","size":827,"stargazers_count":3560,"open_issues_count":100,"forks_count":1663,"subscribers_count":162,"default_branch":"master","last_synced_at":"2024-10-29T14:56:33.482Z","etag":null,"topics":["ajax-autocomplete","autocomplete","autosuggest"],"latest_commit_sha":null,"homepage":"https://www.devbridge.com/sourcery/components/jquery-autocomplete/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devbridge.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2010-05-26T21:38:36.000Z","updated_at":"2024-10-28T16:03:20.000Z","dependencies_parsed_at":"2024-01-13T17:59:08.744Z","dependency_job_id":"5b56dc3a-d47b-4a75-bd38-3436b77817f0","html_url":"https://github.com/devbridge/jQuery-Autocomplete","commit_stats":{"total_commits":272,"total_committers":51,"mean_commits":5.333333333333333,"dds":0.3161764705882353,"last_synced_commit":"8138252b4c6fa994a0d438630ea375308e7f3b11"},"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devbridge%2FjQuery-Autocomplete","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devbridge%2FjQuery-Autocomplete/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devbridge%2FjQuery-Autocomplete/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devbridge%2FjQuery-Autocomplete/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devbridge","download_url":"https://codeload.github.com/devbridge/jQuery-Autocomplete/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222971426,"owners_count":17066397,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ajax-autocomplete","autocomplete","autosuggest"],"created_at":"2024-08-01T18:01:36.834Z","updated_at":"2024-11-07T05:32:09.286Z","avatar_url":"https://github.com/devbridge.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Ajax Autocomplete for jQuery\n\nAjax Autocomplete for jQuery allows you to easily create\nautocomplete/autosuggest boxes for text input fields.\n\nIt has no dependencies other than jQuery.\n\nThe standard jquery.autocomplete.js file is around 13KB when minified.\n\n## API\nThe following sets up autocomplete for input fields where `options` is an object literal that defines the settings to use for the autocomplete plugin.  All available option settings are shown in the tables below.  \n```js\n$(selector).autocomplete(options);\n```\n### General settings (local and Ajax) \n| Setting | Default | Description |\n| :--- | :--- | :--- |\n| `noCache` | `false` | Boolean value indicating whether to cache suggestion results |\n| `delimiter` | optional | String or RegExp, that splits input value and takes last part to as query for suggestions. Useful when for example you need to fill list of  comma separated values. |\n| `minChars` | `1` | Minimum number of characters required to trigger autosuggest |\n| `triggerSelectOnValidInput` | `true` | Boolean value indicating if `select` should be triggered if it matches suggestion |\n| `preventBadQueries` | `true` | Boolean value indicating if it should prevent future Ajax requests for queries with the same root if no results were returned. E.g. if `Jam` returns no suggestions, it will not fire for any future query that starts with `Jam` |\n| `autoSelectFirst` | `false` | If set to `true`, first item will be selected when showing suggestions |\n| `beforeRender` | optional | `function (container, suggestions) {}` called before displaying the suggestions. You may manipulate suggestions DOM before it is displayed |\n| `formatResult` | optional | `function (suggestion, currentValue) {}` custom function to format suggestion entry inside suggestions container |\n| `formatGroup` | optional | `function (suggestion, category) {}` custom function to format group header |\n| `groupBy` | optional | property name of the suggestion `data` object, by which results should be grouped |\n| `maxHeight` | `300` | Maximum height of the suggestions container in pixels |\n| `width` | `auto` | Suggestions container width in pixels, e.g.: 300, `flex` for max suggestion size and `auto` takes input field width |\n| `zIndex` | `9999` | 'z-index' for suggestions container |\n| `appendTo` | optional | Container where suggestions will be appended. Default value `document.body`. Can be jQuery object, selector or HTML element. Make sure to set `position: absolute` or `position: relative` for that element |\n| `forceFixPosition` | `false` | Suggestions are automatically positioned when their container is appended to body (look at `appendTo` option), in other cases suggestions are rendered but no positioning is applied. Set this option to force auto positioning in other cases |\n| `orientation` | `bottom` | Vertical orientation of the displayed suggestions, available values are `auto`, `top`, `bottom`.  If set to `auto`, the suggestions will be orientated it the way that place them closer to middle of the view port |\n| `preserveInput` | `false` | If `true`, input value stays the same when navigating over suggestions |\n| `showNoSuggestionNotice` | `false` | When no matching results, display a notification label |\n| `noSuggestionNotice` | `No results` | Text or htmlString or Element or jQuery object for no matching results label |\n| `onInvalidateSelection` | optional | `function () {}` called when input is altered after selection has been made. `this` is bound to input element |\n| `tabDisabled` | `false` | Set to true to leave the cursor in the input field after the user tabs to select a suggestion |\n\n\n### Event function settings (local and Ajax) \n| Event setting | Function description |\n| :--- | :--- |\n| `onSearchStart` | `function (params) {}` called before Ajax request. `this` is bound to input element |\n| `onHint` | `function (hint) {}` used to change input value to first suggestion automatically. `this` is bound to input element |\n| `onSearchComplete` | `function (query, suggestions) {}` called after Ajax response is processed. `this` is bound to input element. `suggestions` is an array containing the results |\n| `transformResult` | `function(response, originalQuery) {}` called after the result of the query is ready. Converts the result into response.suggestions format |\n| `onSelect` | `function (suggestion) {}` Callback function invoked when user selects suggestion from the list. `this` inside callback refers to input HtmlElement.|\n| `onSearchError` | `function (query, jqXHR, textStatus, errorThrown) {}` called if Ajax request fails. `this` is bound to input element |\n| `onHide` | `function (container) {}` called before container will be hidden |\n\n\n### Local only settings\n| Setting | Default | Description |\n| :--- | :--- | :--- |\n| `lookupLimit` | `no limit` | Number of maximum results to display for local lookup |\n| `lookup` | n/a | Callback function or lookup array for the suggestions. It may be array of strings or `suggestion` object literals |\n| `suggestion` | n/a | Not a settings, but in the context of above row, a suggestion is an object literal with the following format: `{ value: 'string', data: any }` |\n| `lookupFilter` | n/a | `function (suggestion, query, queryLowerCase) {}` filter function for local lookups. By default it does partial string match (case insensitive) |\n\n### Ajax only settings\n| Setting | Default | Description |\n| :--- | :--- | :--- |\n| `serviceUrl` | n/a | Server side URL or callback function that returns serviceUrl string |\n| `type` | `GET` | Ajax request type to get suggestions |\n| `dataType` | `text` | type of data returned from server. Either `text`, `json`  or `jsonp`, which will cause the autocomplete to use jsonp. You may return a json object in your callback when using jsonp |\n| `paramName` | `query` | The name of the request parameter that contains the query |\n| `params` | optional | Additional parameters to pass with the request |\n| `deferRequestBy` | `0` | Number of miliseconds to defer Ajax request |\n| `ajaxSettings` | optional | Any additional [Ajax Settings](http://api.jquery.com/jquery.ajax/#jQuery-ajax-settings) that configure the jQuery Ajax request |\n\n## Default Options\n\nDefault options for all instances can be accessed via `$.Autocomplete.defaults`.\n\n## Instance Methods\n\nAutocomplete instance has following methods:\n\n* `setOptions(options)`: you may update any option at any time. Options are listed above.\n* `clear`: clears suggestion cache and current suggestions.\n* `clearCache`: clears suggestion cache.\n* `disable`: deactivate autocomplete.\n* `enable`: activates autocomplete if it was deactivated before.\n* `hide`: hides suggestions.\n* `dispose`: destroys autocomplete instance. All events are detached and suggestion containers removed.\n\nThere are two ways that you can invoke Autocomplete method. One is calling autocomplete on jQuery object and passing method name as string literal.\nIf method has arguments, arguments are passed as consecutive parameters:\n\n```javascript\n$('#autocomplete').autocomplete('disable');\n$('#autocomplete').autocomplete('setOptions', options);\n```\n\nOr you can get Autocomplete instance by calling autcomplete on jQuery object without any parameters and then invoke desired method.\n\n```javascript\n$('#autocomplete').autocomplete().disable();\n$('#autocomplete').autocomplete().setOptions(options);\n```\n\n## Usage\n\nHtml:\n\n```html\n\u003cinput type=\"text\" name=\"country\" id=\"autocomplete\"/\u003e\n```\n\nAjax lookup:\n\n```javascript\n$('#autocomplete').autocomplete({\n    serviceUrl: '/autocomplete/countries',\n    onSelect: function (suggestion) {\n        alert('You selected: ' + suggestion.value + ', ' + suggestion.data);\n    }\n});\n```\n\nLocal lookup (no Ajax):\n\n```javascript\nvar countries = [\n    { value: 'Andorra', data: 'AD' },\n    // ...\n    { value: 'Zimbabwe', data: 'ZZ' }\n];\n\n$('#autocomplete').autocomplete({\n    lookup: countries,\n    onSelect: function (suggestion) {\n        alert('You selected: ' + suggestion.value + ', ' + suggestion.data);\n    }\n});\n```\n\nCustom lookup function:\n```javascript\n\n$('#autocomplete').autocomplete({\n    lookup: function (query, done) {\n        // Do Ajax call or lookup locally, when done,\n        // call the callback and pass your results:\n        var result = {\n            suggestions: [\n                { \"value\": \"United Arab Emirates\", \"data\": \"AE\" },\n                { \"value\": \"United Kingdom\",       \"data\": \"UK\" },\n                { \"value\": \"United States\",        \"data\": \"US\" }\n            ]\n        };\n\n        done(result);\n    },\n    onSelect: function (suggestion) {\n        alert('You selected: ' + suggestion.value + ', ' + suggestion.data);\n    }\n});\n```\n\n## Styling\n\nGenerated HTML markup for suggestions is displayed below. You may style it any way you'd like.\n\n```html\n\u003cdiv class=\"autocomplete-suggestions\"\u003e\n    \u003cdiv class=\"autocomplete-group\"\u003e\u003cstrong\u003eNHL\u003c/strong\u003e\u003c/div\u003e\n    \u003cdiv class=\"autocomplete-suggestion autocomplete-selected\"\u003e...\u003c/div\u003e\n    \u003cdiv class=\"autocomplete-suggestion\"\u003e...\u003c/div\u003e\n    \u003cdiv class=\"autocomplete-suggestion\"\u003e...\u003c/div\u003e\n\u003c/div\u003e\n```\n\nStyle sample:\n\n```css\n.autocomplete-suggestions { border: 1px solid #999; background: #FFF; overflow: auto; }\n.autocomplete-suggestion { padding: 2px 5px; white-space: nowrap; overflow: hidden; }\n.autocomplete-selected { background: #F0F0F0; }\n.autocomplete-suggestions strong { font-weight: normal; color: #3399FF; }\n.autocomplete-group { padding: 2px 5px; }\n.autocomplete-group strong { display: block; border-bottom: 1px solid #000; }\n```\n\n\n## Response Format\n\nResponse from the server must be JSON formatted following JavaScript object:\n\n```javascript\n{\n    // Query is not required as of version 1.2.5\n    \"query\": \"Unit\",\n    \"suggestions\": [\n        { \"value\": \"United Arab Emirates\", \"data\": \"AE\" },\n        { \"value\": \"United Kingdom\",       \"data\": \"UK\" },\n        { \"value\": \"United States\",        \"data\": \"US\" }\n    ]\n}\n```\n\nData can be any value or object. Data object is passed to formatResults function\nand onSelect callback. Alternatively, if there is no data you can\nsupply just a string array for suggestions:\n\n```json\n{\n    \"query\": \"Unit\",\n    \"suggestions\": [\"United Arab Emirates\", \"United Kingdom\", \"United States\"]\n}\n```\n\n## Non standard query/results\n\nIf your Ajax service expects the query in a different format, and returns data in a different format than the standard response,\nyou can supply the \"paramName\" and \"transformResult\" options:\n\n```javascript\n$('#autocomplete').autocomplete({\n    paramName: 'searchString',\n    transformResult: function(response) {\n        return {\n            suggestions: $.map(response.myData, function(dataItem) {\n                return { value: dataItem.valueField, data: dataItem.dataField };\n            })\n        };\n    }\n})\n```\n\n## Grouping Results\n\nSpecify `groupBy` option of you data property if you wish results to be displayed in groups. For example, set `groupBy: 'category'` if your suggestion data format is:\n\n```javascript\n[\n    { value: 'Chicago Blackhawks', data: { category: 'NHL' } },\n    { value: 'Chicago Bulls', data: { category: 'NBA' } }\n]\n```\n\nResults will be formatted into two groups **NHL** and **NBA**.\n\n## Known Issues\n\nIf you use it with jQuery UI library it also has plugin named `autocomplete`. In this case you can use plugin alias `devbridgeAutocomplete`:\n\n```javascript\n$('.autocomplete').devbridgeAutocomplete({ ... });\n```\n\nIt seems that for mobile Safari click events are only triggered if the CSS of the object being tapped has the cursor set to pointer:\n\n    .autocomplete-suggestion { \n        cursor: pointer;\n    }\n\nSee issue #542\n\n## License\n\nAjax Autocomplete for jQuery is freely distributable under the\nterms of an MIT-style [license](https://github.com/devbridge/jQuery-Autocomplete/blob/master/dist/license.txt).\n\nCopyright notice and permission notice shall be included in all\ncopies or substantial portions of the Software.\n\n## Authors\n\nTomas Kirda / [@tkirda](https://twitter.com/tkirda)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevbridge%2FjQuery-Autocomplete","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevbridge%2FjQuery-Autocomplete","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevbridge%2FjQuery-Autocomplete/lists"}